diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/util/Author.java b/entitymanager/src/test/java/org/hibernate/ejb/test/util/Author.java new file mode 100644 index 0000000000..e35c7f0f70 --- /dev/null +++ b/entitymanager/src/test/java/org/hibernate/ejb/test/util/Author.java @@ -0,0 +1,24 @@ +package org.hibernate.ejb.test.util; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * @author Emmanuel Bernard + */ +@Entity @Table(name="tbl_Author") +public class Author { + @Id + @GeneratedValue + private Integer id; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } +} diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/util/Book.java b/entitymanager/src/test/java/org/hibernate/ejb/test/util/Book.java index c93810f255..039feca057 100644 --- a/entitymanager/src/test/java/org/hibernate/ejb/test/util/Book.java +++ b/entitymanager/src/test/java/org/hibernate/ejb/test/util/Book.java @@ -8,10 +8,18 @@ import javax.persistence.GeneratedValue; * @author Emmanuel Bernard */ @Entity -public class Book { +public class Book extends CopyrightableContent { private Long id; private String name; + public Book() { + super(); + } + + public Book(Author a) { + super(a); + } + @Id @GeneratedValue public Long getId() { diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/util/CopyrightableContent.java b/entitymanager/src/test/java/org/hibernate/ejb/test/util/CopyrightableContent.java new file mode 100644 index 0000000000..37a82dc5c2 --- /dev/null +++ b/entitymanager/src/test/java/org/hibernate/ejb/test/util/CopyrightableContent.java @@ -0,0 +1,31 @@ +package org.hibernate.ejb.test.util; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.ManyToOne; +import javax.persistence.MappedSuperclass; + + +/** + * @author Emmanuel Bernard + */ +@MappedSuperclass +public abstract class CopyrightableContent { + private Author author; + + public CopyrightableContent() { + } + + public CopyrightableContent(Author author) { + this.author = author; + } + + @ManyToOne(fetch = FetchType.LAZY) + private Author getAuthor() { + return author; + } + + private void setAuthor(Author author) { + this.author = author; + } +} diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/util/GetIdentifierTest.java b/entitymanager/src/test/java/org/hibernate/ejb/test/util/GetIdentifierTest.java index ee4def555e..9c555ef359 100644 --- a/entitymanager/src/test/java/org/hibernate/ejb/test/util/GetIdentifierTest.java +++ b/entitymanager/src/test/java/org/hibernate/ejb/test/util/GetIdentifierTest.java @@ -56,7 +56,8 @@ public class GetIdentifierTest extends TestCase { return new Class[] { Book.class, Umbrella.class, - Sickness.class + Sickness.class, + Author.class }; } } diff --git a/entitymanager/src/test/java/org/hibernate/ejb/test/util/IsLoadedTest.java b/entitymanager/src/test/java/org/hibernate/ejb/test/util/IsLoadedTest.java new file mode 100644 index 0000000000..5dac7202e3 --- /dev/null +++ b/entitymanager/src/test/java/org/hibernate/ejb/test/util/IsLoadedTest.java @@ -0,0 +1,36 @@ +package org.hibernate.ejb.test.util; + +import javax.persistence.EntityManager; + +import org.hibernate.ejb.test.TestCase; + +/** + * @author Emmanuel Bernard + */ +public class IsLoadedTest extends TestCase { + + public void testIsLoadedOnPrivateSuperclassProperty() { + EntityManager em = factory.createEntityManager(); + em.getTransaction().begin(); + Author a = new Author(); + Book book = new Book(a); + em.persist( a ); + em.persist( book ); + em.flush(); + em.clear(); + book = em.find( Book.class, book.getId() ); + assertTrue( em.getEntityManagerFactory().getPersistenceUnitUtil().isLoaded( book ) ); + assertFalse( em.getEntityManagerFactory().getPersistenceUnitUtil().isLoaded( book, "author" ) ); + em.getTransaction().rollback(); + em.close(); + } + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { + Author.class, + Book.class, + CopyrightableContent.class + }; + } +}