简体   繁体   中英

Mapping Hibernate : <composite-id> 3

I have a problem mapping to my webapp, I have a table (TacheTicket) contains two primary key and the mapping file I put the following code:

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

but when I execute the program this error appear :

 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

Table definition.

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"才能与表定义保持一致。

I think you are trying to create many to many relationship between tache and ticket . You don't need configuration for the third table in hibernate.

You just have to configure the two tables with many-to-many tag. Checkout this blog.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM