The name of the entity returned by the JPA2 meta-model EntityType.getName() is now PersistentClass.nodeName.

This guarantees that EntityType.getName() == @Entity.name for classes annotated with JPA2.
This commit is contained in:
Tomasz Blachowicz 2010-11-02 22:06:09 +00:00
parent 722f96a9c5
commit b48c5b601c
5 changed files with 11 additions and 9 deletions

View File

@ -33,20 +33,20 @@ import javax.persistence.metamodel.EntityType;
public class EntityTypeImpl<X>
extends AbstractIdentifiableType<X>
implements EntityType<X>, Serializable {
private final String className;
private final String nodeName;
public EntityTypeImpl(
Class<X> javaType,
AbstractIdentifiableType<? super X> superType,
String className,
String nodeName,
boolean hasIdentifierProperty,
boolean isVersioned) {
super( javaType, superType, hasIdentifierProperty, isVersioned );
this.className = className;
this.nodeName = nodeName;
}
public String getName() {
return className;
return nodeName;
}
public BindableType getBindableType() {

View File

@ -94,7 +94,7 @@ public class MetamodelImpl implements Metamodel, Serializable {
EntityTypeImpl entityType = new EntityTypeImpl(
javaType,
superType,
persistentClass.getClassName(),
persistentClass.getNodeName(),
persistentClass.hasIdentifierProperty(),
persistentClass.isVersioned()
);

View File

@ -37,7 +37,7 @@ import javax.persistence.OrderColumn;
/**
* @author Emmanuel Bernard
*/
@Entity
@Entity(name="org.hibernate.ejb.test.metadata.House")
public class House {
private Key key;
private Address address;

View File

@ -97,7 +97,7 @@ public class MetadataTest extends TestCase {
final SingularAttribute<? super Fridge, Long> id2 = fridgeType.getId( Long.class );
assertNotNull( id2 );
assertEquals( Fridge.class.getName(), fridgeType.getName() );
assertEquals( "Fridge", fridgeType.getName() );
assertEquals( Long.class, fridgeType.getIdType().getJavaType() );
assertTrue( fridgeType.hasSingleIdAttribute() );
assertFalse( fridgeType.hasVersionAttribute() );
@ -106,6 +106,7 @@ public class MetadataTest extends TestCase {
assertEquals( 3, fridgeType.getDeclaredAttributes().size() );
final EntityType<House> houseType = factory.getMetamodel().entity( House.class );
assertEquals( "org.hibernate.ejb.test.metadata.House", houseType.getName() );
assertTrue( houseType.hasSingleIdAttribute() );
final SingularAttribute<House, House.Key> houseId = houseType.getDeclaredId( House.Key.class );
assertNotNull( houseId );
@ -113,6 +114,7 @@ public class MetadataTest extends TestCase {
assertEquals( Attribute.PersistentAttributeType.EMBEDDED, houseId.getPersistentAttributeType() );
final EntityType<Person> personType = factory.getMetamodel().entity( Person.class );
assertEquals( "Homo", personType.getName() );
assertFalse( personType.hasSingleIdAttribute() );
final Set<SingularAttribute<? super Person,?>> ids = personType.getIdClassAttributes();
assertNotNull( ids );

View File

@ -32,7 +32,7 @@ import javax.persistence.Entity;
* @author Emmanuel Bernard
*/
@IdClass(Person.PersonPK.class)
@Entity
@Entity(name="Homo") //Person in latin ;)
public class Person {
private String firstName;
private String lastName;