问题描述
我想在包级别创建@GenericGenerator注释,因此它可以通过在包中的所有实体使用。
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)我与注解的package-info.java类:
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)在同一个包,我有以下属性的实体:
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;
}
这是导致异常未知Id.generator:UNIQUE_ID。如果我包括实体类的@GenericGenerator标注,它工作正常。不过,我想这个移到包级别,所以我可以在其他实体重用。
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?
谢谢!
推荐答案
我知道,这个帖子可能是旧的...但我搜索的问题的解决方案,我发现,为我工作的解决方案。所以,我会在这里的情况下张贴这将是有益的人:
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 :
我忘了在cfg.xml文件添加软件包级别的信息
I forgot to add the package level information in the cfg.xml
也许你应该在你的cfg.xml文件中加入这一行:
Maybe you should add this line in your cfg.xml :
<mapping package="com.sample.model"/>
这为我工作:)
这篇关于在包级别注释使用@GenericGenerator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!