【发布时间】:2017-06-25 09:36:59
【问题描述】:
我用:
mysql-connector-java 6.0.6
hibernate 5.2.10.Final
spring 4.3.8.RELEASE
类代码:
public class PhoneNumber extends AbstractValue{
public static final int CELL_PHONE = 1, HOME_PHONE = 2, WORK_PHONE = 3;
public PhoneNumber(String value, Integer type) {
super(value, type);
}
public PhoneNumber() {
this(null,null);
}
}
父类:
public abstract class AbstractValue {
private String value;
private Integer type;
public AbstractValue(String value, Integer type) {
this.value = value;
this.type = type;
}
public String getValue() {
return value;
}
public Integer getType() {
return type;
}
public void setValue(String value) {
this.value = value;
}
public void setType(Integer type) {
this.type = type;
}
}
映射:
<entity class="PhoneNumber" name="PhoneNumber">
<table name="PhoneNumber"/>
<attributes>
<id name="value">
</id>
<basic name="type">
<column nullable="false"/>
</basic>
</attributes>
</entity>
已经试过了:
<entity class="PhoneNumber" name="PhoneNumber">
<table name="PhoneNumber"/>
<attributes>
<id name="value" access="FIELD">
<generated-value strategy="SEQUENCE" generator="IdSeq" />
<sequence-generator name="IdSeq" sequence-name="IdSeq" allocation-size="1" />
</id>
<basic name="type">
<column nullable="false"/>
</basic>
</attributes>
</entity>
<entity class="PhoneNumber" name="PhoneNumber">
<table name="PhoneNumber"/>
<attributes>
<id name="value">
<generated-value strategy="IDENTITY" generator="uuid" />
</id>
<basic name="type">
<column nullable="false"/>
</basic>
</attributes>
</entity>
<entity class="PhoneNumber" name="PhoneNumber">
<table name="PhoneNumber"/>
<attributes>
<id name="value">
<generated-value strategy="TABLE" generator="uuid" />
<table-generator name="uuid" />
</id>
<basic name="type">
<column nullable="false"/>
</basic>
</attributes>
</entity>
并且已经阅读:(所以我希望我不要重复)
org.hibernate.AnnotationException: No identifier specified for entity: com.ubosque.modelo.Ciudadano
org.hibernate.AnnotationException: No identifier specified for entity: login.Users
java.lang.RuntimeException: org.hibernate.AnnotationException: No identifier specified for entity
Org.Hibernate.AnnotationException: No Identifier Specified For Entity I don't have a id in my table
org.hibernate.AnnotationException: No identifier specified for entity using JPA XML entity-mapping
No Identifier specified exception even when it was
How to use @Id with String Type in JPA / Hibernate?
还有更多...
错误:
原因:org.hibernate.AnnotationException:没有为实体指定标识符:com.mayan.nst.server.model.PhoneNumber
如果可能的话,我更喜欢一个解决方案,即不会生成 id
非常感谢您阅读并提供任何帮助
【问题讨论】:
-
AbstractValue是否在某处被标记为实体或映射超类?因为它具有您要使用身份的字段,并且当前无法与您在此处发布的内容保持一致... -
嘿尼尔谢谢你在这里发帖,我不确定我是否完全理解你。
PhoneNumber不是抽象的,id 是常规的String。 -
您想成为“id”的字段在
AbstractValueCLASS 中。AbstractValueCLASS 未标记为“实体”或“映射超类”,因此您不能使用该类中的字段!解决方案是将AbstractValue标记为“映射超类”......就像任何 JPA 文档会告诉你的那样 -
neil stocktin 你说得对!非常感谢你的工作!!!!