eclipse 在此持久性单元中定义的名为“ID_GENERATOR”的重复生成器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20941191/
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 Duplicate generator named "ID_GENERATOR" defined in this persistence unit
提问by czetsuya
I'm currently having this issue which I don't have before I migrated to eclipse-jee-kepler. What I have:
我目前遇到了在迁移到 eclipse-jee-kepler 之前没有的这个问题。我拥有的:
I have 2 classes, base and the extending class:
我有 2 个类,基类和扩展类:
public abstract class BaseEntity implements Serializable {
@Id
@GeneratedValue(generator = "ID_GENERATOR")
@Column(name = "ID")
private Long id;
}
@Entity
@Table(name = "CUSTOMER")
@SequenceGenerator(name = "ID_GENERATOR", sequenceName = "CUSTOMER_SEQ")
public class Customer extends BaseEntity {
}
Before I don't have this validation error but now eclipse is throwing it. I can compile, build and deploy successfully but the error marker is making it hard to pinpoint the compile errors when you really have one.
在我没有这个验证错误但现在 eclipse 抛出它之前。我可以成功编译、构建和部署,但是错误标记使得当你真的有编译错误时很难查明编译错误。
The error seems obvious, it's because I have ID_GENERATOR on all the extending classes. My question: 1.) Can I ignore this error? 2.) Any work around? Possibly using a different approach.
错误似乎很明显,这是因为我在所有扩展类上都有 ID_GENERATOR。我的问题: 1.) 我可以忽略这个错误吗?2.) 任何解决办法?可能使用不同的方法。
回答by czetsuya
I figured the problem, it was more of an eclipse JPA validation setting. To disable:
我想出了这个问题,它更像是一个 Eclipse JPA 验证设置。要禁用:
- Select Window ? Preferences
- Expand Java Persistence ? JPA ? Errors/Warnings
- Click Queries and generators
- Set Duplicate generator definedto:
Ignore
- Click OKto apply changes and close the dialog
- 选择窗口?喜好
- 展开Java 持久性?JPA ? 错误/警告
- 单击查询和生成器
- 将定义的重复生成器设置为:
Ignore
- 单击确定应用更改并关闭对话框
You can also set the value to Warning
instead of Ignore
.
您还可以将该值设置为Warning
而不是Ignore
。
回答by Kevin
For MyEclipse
对于 MyEclipse
1.Windows->Preferences
1.Windows->首选项
2.Myeclipse->Validation->JPA
2.Myeclipse->Validation->JPA
3.Queries and generators
3.查询和生成器
Generators is not defined in the persistence unit;
持久化单元中没有定义生成器;
回答by Ariel Carrera
The generator's name must to be unique by generator and it can be referenced by one or more classes.
生成器的名称对于生成器来说必须是唯一的,并且可以被一个或多个类引用。
The javadoc clearly says:
javadoc 清楚地说:
(Required) A unique generator name that can be referenced by one or more classes to be the generator for primary key values.
(必需)一个唯一的生成器名称,可以被一个或多个类引用以作为主键值的生成器。
According to the java JPA 2.1 specification (SequenceGenerator Annotation of the JPA 2.1 - section 11.1.48):
根据 java JPA 2.1 规范(JPA 2.1 的 SequenceGenerator Annotation - section 11.1.48):
The scope of the generator name is global to the persistence unit (across all generator types)
生成器名称的范围对于持久性单元是全局的(跨所有生成器类型)