2013-08-07 43 views
2

運行程序時出現錯誤,說明Could not determine type for: Integer, at table: t_credential, for columns: [org.hibernate.mapping.Column(id)]休眠:無法確定類型爲:整數

我的t_credential數據庫有一個由應用程序設置的PK列id(不是自動增量)。

這是我的XML映射文件:

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 

<hibernate-mapping> 

<class name="com.x.com.core.pojo.TUIDInfo" table="t_pop3_credential_messageuid"> 
    <id name="id" column="id" type="integer" > 
      <generator class="native" /> 
     </id> 
    <property name="messageUID"><column name="messageUID" /></property> 
    <many-to-one name="cred" column="credential_id" class="com.x.listener.core.imap.Credential" ></many-to-one> 
    </class> 

    <class name="com.x.listener.core.imap.Credential" table="t_credential" > 
     <id name="id" column="id" type="Integer" > 
      <generator class="select" /> 
     </id> 
     <property name="username" column="email" type="String" length="100" /> 
     <property name="password" column="password" type="String" length="100" /> 
     <property name="mailServer" column="mail_server" type="String" length="100" /> 
     <property name="protocol" column="protocol" type="String" length="100" /> 
     <property name="tenant" column="tenant" type="String" /> 
     <property name="host" column="host" type="String" length="100" /> 
    </class> 
</hibernate-mapping> 

我TUID類:

package com.x.com.core.pojo; 

import com.x.listener.core.imap.Credential; 

public class TUIDInfo { 

    private Integer id; 
    private String messageUID;// change accordingly 
    private Credential cred; 



    public TUIDInfo(String messageUID, Credential cred) { 
     super(); 

     this.messageUID = messageUID; 
     this.cred = cred; 

    } 

    public TUIDInfo() { 
     super(); 
    } 

    public Integer getid() { 
     return this.id; 
    } 

    public void setid(Integer id) { 
     this.id = id; 
    } 

    public String getMessageUID() { 
     return this.messageUID; 
    } 

    public void setMessageUID(String messageUID) { 
     this.messageUID = messageUID; 
    } 
    public Credential getCred() { 
     return this.cred; 
    } 

    public void setCred(Credential cred) { 
     this.cred = cred; 
    } 

} 

和我的憑證類:

package com.x.listener.core.imap; 
public class Credential { 
    Integer id; 
    private String host;// change accordingly 
    private String username; 
    private String password;// change accordingly 
    private String mailServer; 
    private String protocol; 
    private String tenant; 


    public Credential(Integer id, String host, String username, 
      String password, String mailServer, String protocol, String tenant) { 
     super(); 
     this.id = id; 
     this.host = host; 
     this.username = username; 
     this.password = password; 
     this.mailServer = mailServer; 
     this.protocol = protocol; 
     this.tenant = tenant; 
    } 

    public Credential() { 
     super(); 
    } 

    public String getProtocol() { 
     return protocol; 
    } 

    public void setProtocal(String protocol) { 
     this.protocol = protocol; 
    } 

    public int getId() { 
     return id; 
    } 

    public void setId(int id) { 
     this.id = id; 
    } 

    public String getHost() { 
     return host; 
    } 

    public void setHost(String host) { 
     this.host = host; 
    } 

    public String getUsername() { 
     return username; 
    } 

    public void setUsername(String username) { 
     this.username = username; 
    } 

    public String getPassword() { 
     return password; 
    } 

    public void setPassword(String password) { 
     this.password = password; 
    } 

    public String getMailServer() { 
     return mailServer; 
    } 

    public void setMailServer(String mailServer) { 
     this.mailServer = mailServer; 
    } 

    public String getTenant() { 
     return tenant; 
    } 

    public void setTenant(String tenant) { 
     this.tenant = tenant; 
    } 

    public void setProtocol(String protocol) { 
     this.protocol = protocol; 
    } 

} 
+0

這可能有助於http://stackoverflow.com/questions/12149874/hibernate-how-to-provide-right-mapping-to-integer-type – sanbhat

回答

2

試圖改變它爲小寫:

<class name="com.x.listener.core.imap.Credential" table="t_credential" > 
     <id name="id" column="id" type="integer" > <!-- Instead of Integer --> 
      <generator class="select" /> 
     </id> 

,只要您使用上面:

<class name="com.x.com.core.pojo.TUIDInfo" table="t_pop3_credential_messageuid"> 
    <id name="id" column="id" type="integer" > 
      <generator class="native" /> 
     </id> 
+0

感謝這有助於。我愚蠢。 – Aneesh

1

刪除type="Integer"type="String"
type屬性包含hibernate映射類型,此映射類型將從Java轉換爲SQL數據類型。
在你的情況下,你可以使用type="int"type="string"