Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
396 views
in Technique[技术] by (71.8m points)

java - Using @GenericGenerator in a package level annotation

I'm trying to create a @GenericGenerator annotation at the package level so it can be used by all the entities in the package.

1) I have a package-info.java class with the annotation:

@org.hibernate.annotations.GenericGenerator(name="unique_id", strategy="uuid")  
package com.sample.model;

2) In that same package, I have an entity with the following attribute:

@Id  
@GeneratedValue(generator="unique_id")  
@Column(name="userid")  
public String userID() {  
    return userID;  
}  

This is resulting in an exception "Unknown Id.generator: unique_id". If I include the @GenericGenerator annotation in the entity class, it works fine. However, I want to move this to the package level so I can reuse it in other entities.

Any ideas where the disconnect could be?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I know that this post may be old ... but I searched for the solution of that problem and I found a solution that worked for me. So I'll post it here in case it would be helpful for someone :

I forgot to add the package level information in the cfg.xml

Maybe you should add this line in your cfg.xml :

<mapping package="com.sample.model"/>

It worked for me :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...