Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-18827 Add testcase #9325

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.bytecode.enhancement.association;

import jakarta.persistence.Entity;


@Entity
class Book extends Document{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.bytecode.enhancement.association;

import jakarta.persistence.ManyToOne;
import jakarta.persistence.MappedSuperclass;


@MappedSuperclass
abstract class Document {

@ManyToOne
protected Person author;

@ManyToOne
private Person translator;

public Person getAuthor() {
return this.author;
}

public void setAuthor(Person author) {
this.author = author;
}

public Person getTranslator() {
return this.translator;
}

public void setTranslator(Person translator) {
this.translator = translator;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.bytecode.enhancement.association;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.hibernate.testing.bytecode.enhancement.EnhancementOptions;
import org.hibernate.testing.bytecode.enhancement.extension.BytecodeEnhanced;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.JiraKey;
import org.junit.jupiter.api.Test;

import java.util.Set;


/**
* @author Thomas Junk
*/
@JiraKey("HHH-18827")
@BytecodeEnhanced
@EnhancementOptions(biDirectionalAssociationManagement = true)
public class OneToManyAssociationWithSuperclassTest {

@Test
public void testEnhancementOneToManyMappedByProtected(){
Person author = new Person();

Book book = new Book();
assertNull(book.getAuthor());

author.setBooksWritten(Set.of(book));
assertNotNull(book.getAuthor());
assertEquals(author, book.getAuthor());
}

@Test
@FailureExpected(
jiraKey = "HHH-18827",
reason = "Byte-code enhancement fails to find private target field in MappedSuperclass")
public void testEnhancementOneToManyMappedByPrivate(){
Person translator = new Person();

Book book = new Book();
assertNull(book.getTranslator());

translator.setBooksTranslated(Set.of(book));
assertNotNull(book.getTranslator());
assertEquals(translator, book.getTranslator());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.orm.test.bytecode.enhancement.association;

import jakarta.persistence.Entity;
import jakarta.persistence.OneToMany;
import java.util.Set;


@Entity
class Person {

@OneToMany(mappedBy = "author")
private Set<Book> booksWritten;

@OneToMany(mappedBy = "translator")
private Set<Book> booksTranslated;

public Set<Book> getBooksWritten() {
return this.booksWritten;
}

public void setBooksWritten(Set<Book> booksWritten){
this.booksWritten = booksWritten;
}

public Set<Book> getBooksTranslated() {
return this.booksTranslated;
}

public void setBooksTranslated(Set<Book> booksTranslated){
this.booksTranslated = booksTranslated;
}
}