运行程序时出现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 :(得分: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>
答案 1 :(得分:1)
删除type="Integer"
和type="String"
type
属性保存hibernate映射类型,此映射类型将从Java转换为SQL数据类型
在您的情况下,您可以使用type="int"
或type="string"
。