簡體   English   中英

映射休眠: <composite-id> 3

[英]Mapping Hibernate : <composite-id> 3

我在映射到我的Web應用程序時遇到問題,我在一個表(TacheTicket)中包含兩個主鍵,並且在映射文件中放置了以下代碼:

<hibernate-mapping>
    <class name="com.model.TacheTicket" table="TACHETICKET">
        <composite-id>
         <key-property name="idTache" column ="idTache" type="com.model.Tache"/>
         <key-property name="idTicket" column="idTicket" type="com.model.Ticket"/>

       </composite-id> 
    </class>
</hibernate-mapping>

但是當我執行程序時,出現此錯誤:

 org.hibernate.MappingException: Could not determine type for: com.model.Tache, at table: TACHETICKET, for columns: [org.hibernate.mapping.Column(idTache)]
    at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:269)
    at org.hibernate.tuple.PropertyFactory.buildStandardProperty(PropertyFactory.java:120)
    at org.hibernate.tuple.component.ComponentMetamodel.<init>(ComponentMetamodel.java:45)
    at org.hibernate.mapping.Component.buildType(Component.java:152)
    at org.hibernate.mapping.Component.getType(Component.java:145)
    at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
    at org.hibernate.mapping.RootClass.validate(RootClass.java:193)
    at org.hibernate.cfg.Configuration.validate(Configuration.java:1108)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1293)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:855)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:774)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1398)
    ... 21 more

表定義。

CREATE TABLE gestionticket.tacheticket (  
        idTachet INT NOT NULL,  idTicket INT NOT NULL, 
        PRIMARY KEY (idTachet, idTicket), INDEX idTicket_idx (idTicket ASC), 
        CONSTRAINT idTache FOREIGN KEY (idTachet) REFERENCES gestionticket.tache (idTache) ON DELETE NO ACTION ON UPDATE NO ACTION, 
        CONSTRAINT idTicket FOREIGN KEY (idTicket) REFERENCES gestionticket.ticket (idTicket) ON DELETE NO ACTION ON UPDATE NO ACTION); 

您需要type="int"才能與表定義保持一致。

我認為您正在嘗試在tacheticket之間建立多對多關系。 您不需要為休眠中的第三個表進行配置。

您只需要使用多對多標記配置兩個表。 查看博客。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM