Results 1 to 7 of 7

Thread: No identifier specified for entity

  1. #1

    Default No identifier specified for entity

    hi,
    I use spring 2.5.5 with hibernate jars that come with the distribution and java 1.5_18
    I WANT to use annotations :
    Code:
    import java.util.List;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    
    @Entity
    @Table(name="trunkgroups")
    public class Trunkgroup {
    
        private int trunkgroup;
        private String name;
        private boolean valid;
        
        public Trunkgroup(){}
    
        @Id
        @GeneratedValue(strategy=GenerationType.AUTO)
        public int getTrunkgroup() {
            return trunkgroup;
        }
    
        
        public void setTrunkgroup(int trunkgroup) {
            this.trunkgroup = trunkgroup;
        }
    
        @Column(name="name")
        public String getName() {
            return name;
        }
    
    
        public void setName(String name) {
            this.name = name;
        }
    
    
        @Column(name="valid")
        public boolean isValid() {
            return valid;
        }
        
        public void setValid(boolean valid) {
            this.valid = valid;
        }
     
    }
    and this :
    Code:
    <bean name="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="dataSource"><ref local="dataSource"/></property>
            <property name="annotatedClasses">
    	     <list>
    	       <value>com.xxx.model.domain.Trunkgroup</value>
    	     </list>
       		</property>
    	    <property name="annotatedPackages">
    	     <list>
    	       <value>com.xxx.model.domain</value>
    	     </list>
    	    </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.jdbc.batch_size">10</prop>
                    <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
    				<prop key="hibernate.cache.use_second_level_cache">false</prop>
                    <prop key="hibernate.cache.use_query_cache">false</prop>
                </props>
            </property>
        </bean>
    when I deploy the application I get :
    Code:
     Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.xxx.model.domain.Trunkgroup
    [21:02:04.484]  at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:671)
    [21:02:04.484]  at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:529)
    [21:02:04.484]  at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:281)
    [21:02:04.484]  at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1125)
    [21:02:04.484]  at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:673)
    [21:02:04.484]  at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
    [21:02:04.484]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1368)
    [21:02:04.484]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1334)
    [21:02:04.484]  ... 63 more
    What do I missed ?
    I know that the javax.persistence annotations have runtime retention.
    What happens that it doesn;t see the @Id. I looked in hibernate faq and there says that @Id must be set...well... I set it... .
    Can someone help ? I'm in a big hurry, thanks.


    regards,
    Viorel

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Try defining the annotations on the attributes directly instead of the getters.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3

    Default

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="trunkgroup")
    private int trunkgroup;
    @Column(name="name")
    private String name;
    @Column(name="valid")
    private boolean valid;

  4. #4

    Default

    thanks for the reply.
    I tried with this and still doesn't work.
    Code:
    @Id
        @Column(name="trunkgroup")
        private int trunkgroup;
        @Column(name="name")
        private String name;
        @Column(name="valid")
        private boolean valid;
    tried a lot of combinations also with @GeneratedValue(strategy=GenerationType.AUTO), @Generated.

    on the forums some say that @Id is not setted, some say that they upgraded the hibernate jars, but @Id is in javax.persistence jar that I took also from spring 2.5.5 dist.

    I really don't understand what I have to do . It should be super simple and shouldn't post any messages on forums. Why is this so hard every time with spring ? It's getting on my nervs especially when I have deadlines. I worked with annotations with JPA on jboss and never seen this problems.

    regards,
    Viorel

  5. #5
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Well it could be the hibernate version (that is at least what does the scanning and detection NOT spring). I also see that you have annotated classes and packages set, try removing the packages stuff that shouldn't be needed.

    Make sure that there aren't conflicting classes (duplicate jar or duplicate packages which screw up matching). If you use hibernate the javax classes are part of the hibernate annotations jar.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  6. #6

    Default

    hi,
    cleared the problem. I had a very messed up classpath meaning a lot of jars from a a couple of different apps in the server's lib dir; I put the jas from the server's instalation and then the dependency jars that I needed from spring 2.5.6 dist and worked.

    thanks,
    Viorel

  7. #7
    Join Date
    Oct 2011
    Posts
    1

    Default Annotaion Mapping

    I was facing the same problem, to resolve this make sure these two steps done :

    1. add your Entity in hibernate configuration file like
    <hibernate-configuration>
    <session-factory>
    <mapping class="uk.co.ecube.indx.port.model.bo.Address"/>
    <mapping class="uk.co.ecube.indx.port.model.bo.Professional "/>
    </session-factory>
    </hibernate-configuration>



    2. put Jar in project build path :

    hibernate-commons-annotations
    hibernate-core

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •