HHH-5258 add tests on isLoaded and superclasses and private properties

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19600 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2010-05-25 13:07:42 +00:00
parent 85e15cfbdf
commit 66ef8d95c5
5 changed files with 102 additions and 2 deletions

View File

@ -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;
}
}

View File

@ -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() {

View File

@ -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;
}
}

View File

@ -56,7 +56,8 @@ public class GetIdentifierTest extends TestCase {
return new Class[] {
Book.class,
Umbrella.class,
Sickness.class
Sickness.class,
Author.class
};
}
}

View File

@ -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
};
}
}