-->
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: Issues with inheriting @Id from @MappedSuperclass
PostPosted: Fri Feb 24, 2006 4:27 am 
Newbie

Joined: Fri Feb 24, 2006 3:50 am
Posts: 1
Hi,

I'm trying to map a class hierarchy with the primary key defined in an abstract base class.
Persisting and loading entities works fine, so does automatic schema generation. But when trying to generate the ddl or the xml-mappings using the hibernatetool ant-task I get an AnnotationException complaining that no identifier is specified for my entities.

Seems pretty dumb to post this to the EJB3-subforum? I posted this as a bug report for the tools project, but was rejected stating that it's the annotation core that complains...

Hibernate version: Hibernate 3.1.1, JDK1.5.0_03, Hibernate Annotations 3.1 beta 8, Hibernate Tools 3.1 beta4

Name and version of the database you are using: Oracle 10.2.0.1.0

Mapping documents:

hibernate.cfg.xml:

Code:
<hibernate-configuration>
    <session-factory name="hibernate/SessionFactory">
      <!-- Datasource-URL -->
      <property name="hibernate.connection.datasource">java:comp/env/jdbc/conn</property>
        <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
       
      
      <!-- Enable Hibernate's automatic session context management -->
      <property name="hibernate.current_session_context_class">thread</property>
      <!-- Disable the second-level cache -->
      <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
      <!-- Echo all executed SQL to stdout -->
      <property name="hibernate.show_sql">true</property>
      <!-- Update the database schema on startup -->
      <property name="hibernate.hbm2ddl.auto">update</property>

      <!-- Mappings -->
      <mapping class="some.package.SomeEntity"/>
      
    </session-factory>
</hibernate-configuration>


Note that the base class is not mapped - on the one hand it works fine without, on the other I get an AnnotationException trying when to do that:

Code:
org.hibernate.AnnotationException: Annotated class should have a @javax.persistence.Entity, @javax.persistence.Embeddable or @javax.persistence.EmbeddedSuperclass annotation: some.package.AbstractPersistentObject
   at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:334)
   at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:266)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:199)
   at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:996)
   at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:56)
   at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:179)
   at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:43)
   at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:143)
   at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
   at org.apache.tools.ant.Task.perform(Task.java:364)
   at org.apache.tools.ant.Target.execute(Target.java:341)
   at org.apache.tools.ant.Target.performTasks(Target.java:369)
   at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
   at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
   at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
   at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
   at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
   at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
   at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)


AbstractPersistentObject:

Code:
@MappedSuperclass
public abstract class AbstractPersistentObject {
   
   @Id @GeneratedValue(strategy=GenerationType.SEQUENCE)
   private long id;

   public long getId() {
      return id;
   }
   
}


SomeEntity:

Code:
@Entity
@Table
public class SomeEntity extends AbstractPersistentObject {
   @Column
   private int refNo;

   public int getRefNo() {
      return refNo;
   }

   public void setRefNo(int refNo) {
      this.refNo = refNo;
   }
...


The configuration is processed by a pretty stupid HibernateUtil-class
Code:
public final class HibernateUtil {

    private static SessionFactory sessionFactory;

    private static final String CONFIG_FILE = "/hibernate.cfg.xml";

    public static void init() {
        try {
            // Create the SessionFactory from hibernate.cfg.xml
            new AnnotationConfiguration().configure(CONFIG_FILE).buildSessionFactory();
        } catch (Throwable ex) {
            // Make sure you log the exception, as it might be swallowed
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new RuntimeException(ex);
        }
    }

    private static SessionFactory getSessionFactory() {
        if (sessionFactory == null) {
            try {
                InitialContext ctx = new InitialContext();
                sessionFactory = (SessionFactory) ctx.lookup("hibernate/SessionFactory");
            } catch (NamingException e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            }
        }
        return sessionFactory;
    }
}
}


Full stack trace of any exception that occurs:

Code:
[hibernatetool] Executing Hibernate Tool with a Hibernate Annotation/EJB3 Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] 09:15:40,888  INFO Environment:479 - Hibernate 3.1.1
[hibernatetool] 09:15:40,908  INFO Environment:509 - hibernate.properties not found
[hibernatetool] 09:15:40,908  INFO Environment:525 - using CGLIB reflection optimizer
[hibernatetool] 09:15:40,918  INFO Environment:555 - using JDK 1.4 java.sql.Timestamp handling
[hibernatetool] 09:15:41,018  INFO Configuration:1330 - configuring from file: top.hibernate.cfg.xml
[hibernatetool] 09:15:41,238  INFO Configuration:1407 - Configured SessionFactory: hibernate/SessionFactory
[hibernatetool] 09:15:41,298  INFO AnnotationBinder:340 - Binding entity from annotated class: java.lang.Class
[hibernatetool] 09:15:41,368  INFO EntityBinder:298 - Bind entity some.package.SomeEntity on table SOMENENTITY

BUILD FAILED
D:\Appl\top\prototype\bin\build.xml:444: org.hibernate.AnnotationException: No identifier specified for entity: some.package.SomeEntity
   at org.apache.tools.ant.Task.perform(Task.java:373)
   at org.apache.tools.ant.Target.execute(Target.java:341)
   at org.apache.tools.ant.Target.performTasks(Target.java:369)
   at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
   at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
   at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
   at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
   at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
   at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
   at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
Caused by: org.hibernate.AnnotationException: No identifier specified for entity: some.package.SomeEntity
   at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:648)
   at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:266)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:199)
   at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:996)
   at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:56)
   at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:179)
   at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:43)
   at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:143)
   at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
   at org.apache.tools.ant.Task.perform(Task.java:364)
   ... 9 more
--- Nested Exception ---
org.hibernate.AnnotationException: No identifier specified for entity: some.package.SomeEntity
   at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:648)
   at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:266)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:199)
   at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:996)
   at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:56)
   at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:179)
   at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:43)
   at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:143)
   at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
   at org.apache.tools.ant.Task.perform(Task.java:364)
   at org.apache.tools.ant.Target.execute(Target.java:341)
   at org.apache.tools.ant.Target.performTasks(Target.java:369)
   at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
   at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
   at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:40)
   at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
   at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
   at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
   at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 15, 2006 2:25 pm 
Newbie

Joined: Tue Apr 04, 2006 10:58 pm
Posts: 6
I am having the same issue. Has anyone found a solution to this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 6:00 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I'm sure that this potential bug is not in the latest releases. Please upgrade

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 18, 2006 7:16 pm 
Newbie

Joined: Tue Apr 04, 2006 10:58 pm
Posts: 6
For me at least, it was a dependency problem. No bug, it works.


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.