Eclipse:持久性单元中未定义名为“system-uuid”的生成器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12465048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eclipse: No generator named "system-uuid" is defined in the persistence unit
提问by cmdematos
I have a maven enabled project imported into Eclipse. From Eclipse, I get an error "No generator named "system-uuid" is defined in the persistence unit" on the system-uuid portion of the following lines:
我有一个已启用 Maven 的项目导入到 Eclipse 中。在 Eclipse 中,我在以下几行的 system-uuid 部分收到错误“没有在持久性单元中定义名为“system-uuid”的生成器”:
@Id @GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(length = 36)
public String getId() {
return id;
}
The project builds correctly from the command line. What is causing Eclipse to generate this error and how do I fix it?
该项目从命令行正确构建。是什么导致 Eclipse 生成此错误,我该如何解决?
The persistence file looks like this..
持久性文件看起来像这样..
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="xxxx"/>
</persistence>
回答by Karen Butzke
You can turn the error off/down under Preferences -> Java Persistence -> JPA -> Errors/Warnings under 'Queries and Generators' by changing the error 'Generator is not defined in the persistence unit' to a warning.
您可以在“查询和生成器”下的“首选项”->“Java 持久性”->“JPA”->“错误/警告”下关闭/关闭错误,方法是将“生成器未在持久性单元中定义”错误更改为警告。
This looks like a bug in the Hibernate Tools extension of Dali in Eclipse.You could report this to Hibernate Tools or maybe this is fixed in a more recent version.
这看起来像是 Eclipse 中 Dali 的 Hibernate Tools 扩展中的一个错误。您可以将此报告给 Hibernate Tools,或者这可能会在更新的版本中得到修复。
回答by jeff
Eclipse Luna: This seems to work
Eclipse Luna:这似乎有效
Project -> Clean
回答by roehrijn
Newer versions of Eclipse' JPA support seem to depend on the order of Annotations. You are defining the generator after you try to use em.
较新版本的 Eclipse 的 JPA 支持似乎取决于注释的顺序。在尝试使用 em 之后,您正在定义生成器。
This will work:
这将起作用:
@Id
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@GeneratedValue(generator = "system-uuid")
@Column(length = 36)
public String getId() {
return id;
}
However the order of annotations in Java must not have a meaning. So Karen is right, it seems to be a bug.
然而,Java 中的注解顺序一定没有意义。所以Karen是对的,这似乎是一个错误。
回答by Saadane Othmane
I had almost same error - I used my custom id generator - in eclipse mars after importing my project from github.
从 github 导入我的项目后,我在 eclipse mars 中遇到了几乎相同的错误 - 我使用了我的自定义 id 生成器。
the error : No generator named “idGenEchantillon” is defined in the persistence unit
错误: 持久性单元中未定义名为“idGenEchantillon”的生成器
So my answer is not really for the main question, but for other developers having same error as mine which can see here.
所以我的答案并不是真正针对主要问题,而是针对与我的错误相同的其他开发人员,可以在这里看到。
the code :
编码 :
@Id
@GenericGenerator(name = "idGenEchantillon", strategy = "com.labo.model.KeyGenaratorForEchantillon")
@GeneratedValue(generator ="idGenEchantillon")
@Column(name = "ID_ECHANTILLON", length = 12)
private String idEchantillon;
I used maven to manage dependencies.
我使用 maven 来管理依赖项。
- I've removed the JPA facet from my project => every time I update my prject using Maven, the project take the JPA facet again => the error stay.
- I've disabled "JPA Configurator" option of Maven : Window >> Preferences >> Maven >> Java EE Integration , then uncheck "JPA CONFIGURATOR", after that I've update my project using Maven => the error is gone.
- 我已经从我的项目中删除了 JPA 方面 => 每次我使用 Maven 更新我的项目时,项目都会再次采用 JPA 方面 => 错误仍然存在。
- 我已禁用 Maven 的“JPA Configurator”选项:Window >> Preferences >> Maven >> Java EE Integration,然后取消选中“JPA CONFIGURATOR”,之后我使用 Maven 更新了我的项目 => 错误消失了。