2014-07-17 175 views
0

我有一個問題映射到我的web應用程序,我有一個表(TacheTicket)包含兩個主鍵和映射文件,我把下列代碼:映射休眠:<複合-ID> 3

<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); 
+0

可以提供表結構,即字段名和類型 – bitkot

+0

@AmitChotaliya表結構:CREATE TABLE'gestionticket'.'tacheticket'( 'idTachet' INT NOT NULL, 'idTicket' INT NOT NULL, PRIMARY KEY ('idTachet','idTicket') INDEX'idTicket_idx'('idTicket' ASC), 約束'idTache' 外鍵('idTachet') 參考'gestionticket'.'tache'('idTache') ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT'idTicket' FOREIGN KEY('idTicket') REFERENCES'gestionticket'.'tic ('idTicket') ON DELETE NO ACTION ON UPDATE NO ACTION); – user3850191

+0

在你的問題,格式化,而不是在評論。 – philipxy

回答

0

我認爲您正在嘗試創建tacheticket之間的多對多關係。 您不需要在休眠中配置第三張表。

您只需使用多對多標籤配置兩個表。 結帳this博客。

0

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

+0

但我可以在哪裏設置IDTicket是表格票的主鍵,甚至是IDTach ... – user3850191

+0

這是一個不同的問題。閱讀[this](http://stackoverflow.com/help/how-to-ask)和[this](http://stackoverflow.com/help/mcve)。並寫得很清楚。寫就像我們不知道你做了什麼或你想做什麼。因爲我們沒有。 – philipxy