映射Hibernate:<composite-id> 3 </composite-id>

时间:2014-07-17 17:25:20

标签: java hibernate composite-primary-key

我有一个问题映射到我的webapp,我有一个表(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); 

2 个答案:

答案 0 :(得分:0)

您需要type="int"同意表格定义。

答案 1 :(得分:0)

我认为您正在尝试在tacheticket之间建立多对多的关系。 你不需要在休眠状态下为第三个表配置。

您只需要使用多对多标记配置两个表。 结帐this博客。