0

I use :

mysql-connector-java 6.0.6

hibernate 5.2.10.Final

spring 4.3.8.RELEASE

Class code :

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);
    }

}

Parent class :

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;
    }
}

Mapping :

<entity class="PhoneNumber" name="PhoneNumber">
        <table name="PhoneNumber"/>
        <attributes>
            <id name="value">
            </id>
            <basic name="type">
            <column nullable="false"/>
        </basic>
    </attributes>
</entity>

Already tried :

<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>

And already read : (so i hope i don't do duplicate)

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

string id generator

How to use @Id with String Type in JPA / Hibernate?

and some more...

error :

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.mayan.nst.server.model.PhoneNumber

IF its possible i was prefer a solution were the id will NOT be generated

Thanks you very mutch for read, and for any help

4
  • 1
    Is AbstractValue marked as an entity or mapped-superclass somewhere? Because it has the field you want to use identity and it isn't currently persistable with what you post there ... Commented Jun 25, 2017 at 12:16
  • Hey neil thank you for post here, i don't sure i understand you completely. the PhoneNumber is not abstract and the id is regular String. Commented Jun 25, 2017 at 12:34
  • 1
    The FIELD that you want to be the "id" is in AbstractValue CLASS. AbstractValue CLASS is NOT marked as "entity" or "mapped-superclass" so you cannot use fields in that class !! Solution is to mark AbstractValue as "mapped-superclass" ... like any JPA doc would tell you Commented Jun 25, 2017 at 12:37
  • neil stocktin you right ! thank you very so much its work !!!! Commented Jun 25, 2017 at 12:49

1 Answer 1

0

Thanks to Neil Stocktin the problem was that i tried to get superclass property from this child. (not working). solution will be add

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

        </id>
    </attributes>
</entity>

and remove the from the child

Update

better solution, to separate the super class childrens tables. use :

<mapped-superclass class="AbstractValue">
    <attributes>
        <id name="value"/>
        <basic name="type">
            <column nullable="false"/>
        </basic>
    </attributes>
</mapped-superclass>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.