我用:
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
非常感谢你阅读,以及任何帮助
答案 0 :(得分:0)
感谢Neil Stocktin问题是我试图从这个孩子那里获得超类属性。 (不工作)。解决方案将添加
<entity class="AbstractValue">
<attributes>
<id name="value">
</id>
</attributes>
</entity>
并从孩子那里删除
<强>更新强>
更好的解决方案,将超级儿童桌分开。使用:
<mapped-superclass class="AbstractValue">
<attributes>
<id name="value"/>
<basic name="type">
<column nullable="false"/>
</basic>
</attributes>
</mapped-superclass>