-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: @Entity.name and EntityBinder
PostPosted: Fri May 04, 2007 9:58 am 
Newbie

Joined: Fri May 04, 2007 9:30 am
Posts: 2
Location: SP, Brasil
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 2:40 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is expected, Hibernate entity-name and the specification Entity.name are unfortunately 2 different notions.

Should the criteria API react to the entity alias, that a good question though.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 2:41 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2597

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 04, 2007 2:53 pm 
Newbie

Joined: Fri May 04, 2007 9:30 am
Posts: 2
Location: SP, Brasil
Thanks Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.