-->
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.  [ 2 posts ] 
Author Message
 Post subject: Unknown Id.generator: hibernate-increment
PostPosted: Wed Apr 01, 2009 11:01 am 
Newbie

Joined: Tue Aug 19, 2008 9:30 am
Posts: 10
hi,

i have a problem with the GenericGenerator-GeneratedValue-annotations.
When using this simple class

Code:
import javax.persistence.*;
import org.hibernate.annotations.GenericGenerator;

@MappedSuperclass
@GenericGenerator( name="hibernate-increment",strategy="increment")
public abstract class IDobject
{
  protected Long id;

  @Id @GeneratedValue(generator="hibernate-increment")
  public Long getID()
  {
    return id;
  }

  final public void setID( Long id )
  {
    if( this.id!=null ){
      throw new IllegalStateException( "id already set" );
    }
     
    this.id = id;
  }
}


i get this exception
Caused by: org.hibernate.AnnotationException: Unknown Id.generator: hibernate-increment
at org.hibernate.cfg.BinderHelper.makeIdGenerator(BinderHelper.java:428)
at org.hibernate.cfg.AnnotationBinder.bindId(AnnotationBinder.java:1901)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1279)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:754)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:546)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:291)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1319)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
at server.persistence.init.AnnotatedConfigurationWrapper.init(AnnotatedConfigurationWrapper.java:52)
at server.persistence.init.AnnotatedConfigurationWrapper.<init>(AnnotatedConfigurationWrapper.java:39)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:84)
... 34 more


Is this problem, that the class is not an @Entity?

Regards,
Stephan


Top
 Profile  
 
 Post subject: Re: Unknown Id.generator: hibernate-increment
PostPosted: Thu Apr 02, 2009 9:30 am 
Newbie

Joined: Tue Aug 19, 2008 9:30 am
Posts: 10
simon.void wrote:
Is this problem, that the class is not an @Entity?

Seems that way. When i insert
Code:
@org.hibernate.annotations.GenericGenerator( name="hibernate-increment",strategy="increment")

in every @Entity-class that extends IdObject, the Id.generator hibernate-increment is found. But it would be really nice if that wouldn't be neccessary.

I tried to write the @GernericGenerator-Tag in an package-info.java file
Code:
@org.hibernate.annotations.GenericGenerator( name="hibernate-increment",strategy="increment")

package server.domainobjects;

which is located in the package where IdObject and all it's subclasses are in. Then i added this package to the AnnotatedConfiguration

Code:
annotationConfiguration.addPackage( "server.domainobjects" );

but this didn't work. Doing it in hibernate.cfg.xml via <mapping package="server.domainobjects"/> didn't cut it either.

Am i missing something?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.