-->
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: GenericGenerator at package-level not working
PostPosted: Sun Feb 16, 2014 5:01 pm 
Newbie

Joined: Wed Apr 24, 2013 7:51 am
Posts: 3
Hi all! I'm trying to specify a GenericGenerator at package-level but, no matter what I try I always end up with the same exception.

package-info.java

Code:
@GenericGenerator(
        name = "mygenerator",
        strategy = "org.hibernate.id.enhanced.TableGenerator",
        parameters = {
            @Parameter(name = "sequence_name", value = "MY_SEQUENCE"),
            @Parameter(name = "initial_value", value = "1000"),
            @Parameter(name = "optimizer", value = "pooled"),
            @Parameter(name = "increment_size", value = "10")
        }
    )
package com.somepackage.domain;


import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;


My Entity

Code:
package com.somepackage.domain;


import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.validation.constraints.NotNull;

@Entity
public class Account{
   @Id
   @GeneratedValue(generator = "mygenerator")
   private Long id;


    @NotNull
    private String name;


    //...

}


The Exception

Quote:
Caused by: org.hibernate.AnnotationException: Unknown Id.generator: mygenerator
at org.hibernate.cfg.BinderHelper.makeIdGenerator(BinderHelper.java:639)
at org.hibernate.cfg.AnnotationBinder.processId(AnnotationBinder.java:2159)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:2065)
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:767)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:686)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3540)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3494)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1379)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1784)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1868)


I'm using Tomcat7 and OpenJDK7

Regards!


Top
 Profile  
 
 Post subject: Re: GenericGenerator at package-level not working
PostPosted: Sun Feb 16, 2014 8:05 pm 
Newbie

Joined: Wed Apr 24, 2013 7:51 am
Posts: 3
I solved the problem myself. I needed to tell my sessionFactory to scan that package for metadata.

Code:
sessionFactory.setAnnotatedPackages(new String[]{"com.somepackage.domain"});


Or, if you're using XML, this should be placed in your Hibernate configuration file.

Code:
<resource package="com.somepackage.domain"></resource>


I posted the example in my blog.

http://arecordon.blogspot.com.ar/2014/02/hibernate-advanced-features-package.html


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.