Hibernate,没有针对实体指定的标识符,用于映射字符串ID



i使用:

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:未针对实体指定的标识符:com.ubosque.modelo.ciudadano

org.hibernate.AnnotationException:未针对实体指定的标识符:login.users

java.lang.runtimeException:org.hibernate.annotationException:未针对实体指定标识符

org.hibernate.AnnotationException:没有为实体指定的标识符,我的表中没有ID

org.hibernate.AnnotationException:未针对实体指定使用JPA XML实体映射

即使是

,也没有指定例外的标识符

字符串ID Generator

如何将@id与jpa/hibernate中的字符串类型一起使用?

以及更多...

错误:

由:org.hibernate.annotationException引起:未针对实体指定的标识符:com.mayan.nst.server.model.model.phonenumber

如果可能的话,我更喜欢解决方案,即ID不会生成

非常感谢您的阅读和任何帮助

多亏了尼尔·斯托克(Neil Stocktin(,问题是我试图从这个孩子那里获得超级类的财产。(不工作(。解决方案将添加

<entity class="AbstractValue">
    <attributes>
        <id name="value">
        </id>
    </attributes>
</entity>

并从孩子中删除

update

更好的解决方案,以分离超级阶级的儿童表。使用:

<mapped-superclass class="AbstractValue">
    <attributes>
        <id name="value"/>
        <basic name="type">
            <column nullable="false"/>
        </basic>
    </attributes>
</mapped-superclass>

最新更新