java.lang.Long没有持久的id属性

时间:2016-04-12 10:37:01

标签: java hibernate jpa

我试图将实体从第三方库持久化到数据库,所以我使用的是router.dev.js方法,而不是使用Java持久性注释。

我的router.min.js文件如下所示:

orm.xml

然而,当我运行上述内容时,我收到以下错误:

orm.xml

Ticket.java

<?xml version="1.0" encoding="UTF-8" ?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm 
    http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
    version="1.0">

    <description>External entities</description>
    <package>org.zendesk.client.v2.model</package>
    <mapped-superclass class="org.zendesk.client.v2.model.Request">
        <attributes>
            <embedded-id name="id"></embedded-id>
        </attributes>
    </mapped-superclass>
    <entity class="Ticket">
        <pre-update method-name="update" />

        <attributes>    

            <id name="id">
                <generated-value/>
            </id>

        </attributes>     
    </entity>
</entity-mappings>

Request.java

    Caused by: javax.persistence.PersistenceException: Unable to build entity manager factory
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:66)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
    at org.springframework.orm.jpa.LocalEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalEntityManagerFactoryBean.java:96)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:319)
    at org.apache.camel.component.jpa.JpaEndpoint.createEntityManagerFactory(JpaEndpoint.java:510)
    at org.apache.camel.component.jpa.JpaEndpoint.getEntityManagerFactory(JpaEndpoint.java:223)
    at org.apache.camel.component.jpa.JpaEndpoint.validate(JpaEndpoint.java:503)
    at org.apache.camel.component.jpa.JpaEndpoint.createProducer(JpaEndpoint.java:145)
    at org.apache.camel.impl.ProducerCache.doGetProducer(ProducerCache.java:439)
    ... 76 more
Caused by: org.hibernate.AnnotationException: java.lang.Long has no persistent id property: org.zendesk.client.v2.model.Ticket.id
    at org.hibernate.cfg.AnnotationBinder.bindComponent(AnnotationBinder.java:2478)
    at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:2164)
    at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:906)
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:733)
    at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:245)
    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:848)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:876)
    at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:58)
    ... 84 more

有谁知道我做错了什么?

1 个答案:

答案 0 :(得分:2)

在XML元数据中声明字段时,您只能在它们出现的类的元数据中定义它们,因此在您的情况下,应为类{{1}定义字段“ id ” (不是Request Request)。您还应该在请求“ embedded-id ”中将其定义为“ id ”类型。

您可以在类Ticket的元数据中定义字段“ id ”的唯一时间是使用 attribute-override 覆盖元数据的特定部分