2

I am now using Hibernate 5.2.4.Final (upgraded from 5.2.3 to see if this would fix the error, but still no success).

I have the following SQL:

 CREATE TABLE Token (
     tokenId        BIGINT PRIMARY KEY
    ,uuid           UUID
    ,state          INTEGER
    ,creationDate   TIMESTAMP
    ,expirationDate TIMESTAMP
    ,userId         BIGINT REFERENCES MyUser(id)
);
CREATE SEQUENCE TokenIdSeq;

and the following entity in the mapping file:

<entity name="Token" class="com.library_provider.Token" access="FIELD">
    <id name="tokenId">
        <generated-value strategy="SEQUENCE" generator="TokenIdSeq" />
        <sequence-generator name="TokenIdSeq" sequence-name="TokenIdSeq" allocation-size="1" />
    </id>
    <basic name="uuid" />
    <basic name="state" />
    <basic name="creationDate" />
    <basic name="expirationDate" />
    <many-to-one name="userData" class="com.company.MyUser" column="userId" />
</entity>

The Token class is:

public class Token implements Serializable {

    private static final long serialVersionUID = 12432342342423400L;

    private Long tokenId;

    private UUID uuid;

    private Integer state;

    private Date creationDate;

    private Date expirationDate;

    public UserData userData;
//....
}

I am getting the following exception upon booting Tomcat:

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.library_provider.Token
    at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:231)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:719)
    at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:249)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:222)
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:265)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:846)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:873)
    at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:151)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
    ... 21 more

I am using the JPA XML mapping file instead of annotations. Why is this exception being thrown? My other entities are working fine, with the difference that I am using <id name="id"> in these fields, but in this case, I cannot decide/change the name of the tokenId field.

Daniel Gray
  • 1,697
  • 1
  • 21
  • 41

1 Answers1

0

The JPA mapping file is missing the <attributes> tag, inside the <entity>.

It should be:

<entity name="Token" class="com.library_provider.Token" access="FIELD">
    <attributes>
        <id name="tokenId">
            <generated-value strategy="SEQUENCE" generator="TokenIdSeq" />
            <sequence-generator name="TokenIdSeq" sequence-name="TokenIdSeq" allocation-size="1" />
        </id>
        <basic name="uuid" />
        <basic name="state" />
        <basic name="creationDate" />
        <basic name="expirationDate" />
        <many-to-one name="userData" class="com.company.MyUser" column="userId" />
    </attributes>

Daniel Gray
  • 1,697
  • 1
  • 21
  • 41