hibernate-annotations-3.2.1.ga
hibernate-3.2.3.ga
I'm trying to use @Entity(name="Test") to map a very simple pojo, but hibernate seems to ignore entity name, ie.: session.createCritirea("Test").list() throws "org.hibernate.MappingException: Unknown entity: Test" but session.createCritirea(myPojoClassName).list() works.
Doing some debug I found:
class: org.hibernate.cfg.annotations.EntityBinder
method: public void bindEntity()
Code:
public class EntityBinder {
private String name;
...
private void bindEjb3Annotation(Entity ejb3Ann) {
if ( ejb3Ann == null ) throw new AssertionFailure( "@Entity should always be not null" );
if ( BinderHelper.isDefault( ejb3Ann.name() ) ) {
name = StringHelper.unqualify( annotatedClass.getName() );
}
else {
name = ejb3Ann.name();
}
}
...
public void bindEntity() {
persistentClass.setAbstract( annotatedClass.isAbstract() );
persistentClass.setClassName( annotatedClass.getName() );
//persistentClass.setDynamic(false); //no longer needed with the Entity name refactoring?
persistentClass.setEntityName( annotatedClass.getName() );
...
Is the last line correct? Shouldn't it read:
Code:
persistentClass.setEntityName(name);
The way it is written it ignores @Entity.name and uses the class name as entity name.
Should I post it to JIRA?
PS: svn trunk version of this class seems to have the same problem
____
My Pojo:
Code:
package exp.persist.domain;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* Test Pojo
*/
@Entity(name = "Test")
@Table(name = "rolha")
public class Rolha
{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column
private double diametro;
@Column
private double comprimento;
...
My Test:
Code:
public static void main(String[] args) {
AnnotationConfiguration config = new AnnotationConfiguration();
config.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
config.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver");
config.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:baseball");
config.setProperty("hibernate.connection.username", "sa");
config.setProperty("hibernate.connection.password", "");
config.setProperty("hibernate.connection.pool_size", "1");
config.setProperty("hibernate.connection.autocommit", "true");
config.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.HashtableCacheProvider");
config.setProperty("hibernate.hbm2ddl.auto", "create-drop");
config.setProperty("hibernate.show_sql", "true");
config.addAnnotatedClass(Rolha.class);
SessionFactory sf = config.buildSessionFactory();
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
session.createCriteria("exp.persist.domain.Rolha").list(); //works!!
session.createCriteria("Test").list(); //throws org.hibernate.MappingException: Unknown entity: Test
tx.commit();
}
My classpath:
Code:
dom4j-1.6.1.jar
antlr-2.7.6.jar
asm-1.5.3.jar
asm-attrs-1.5.3.jar
ehcache-1.2.3.jar
stax-api-1.0.jar
jaxme-api-0.3.jar
hibernate-3.2.3.ga.jar
persistence-api-1.0.jar
relaxngDatatype-20030807.jar
hibernate-annotations-3.2.1.ga.jar
xsdlib-20030807.jar
xpp3-1.1.3.3.jar
junit-3.8.2.jar
commons-logging-1.0.4.jar
cglib-2.1_3.jar
jta-1.0.1B.jar
commons-collections-2.1.1.jar
pull-parser-2.jar
hsqldb-1.7.3.3.jar
jaxen-1.1-beta-6.jar