我知道我错过了一些非常愚蠢和轻微的东西。从DB到hibernate pojo的映射中的某些东西是不对的。我无法指责它。请帮我识别错误。
我想知道为什么hibernate会在DeviceDetails类上抛出异常。我在HBM文件中提到了CDeviceDetails(一个用于hibernate的pojo)。
com.mycompany.common.contracts.CDeviceDetails
@XmlRootElement
public class CDeviceDetails implements IDeviceDetails, IDeviceDetailsSetters,
IAuthenticable {
// Identity Parameters
private String deviceUniqueIdentity;
// Device Parameters
private String networkMacID;
private String model;
private String manufacturer;
private String androidVersion;
private Date firstTimeInstalledDate;
private String buildID;
private String fingerPrint;
private String board;
private String bootloader;
private String hardware;
private String id;
private String product;
private String serial;
// Dates for events
private Date activationDate;
private Date lastUpdatedDate;
// Status of device
private int rowStatus;
public CDeviceDetails() {
}
public CDeviceDetails(String deviceUniqueIdentity, String networkMacID,
String model, String manufacturer, String androidVersion,
Date firstTimeInstalledDate, String buildID, String fingerPrint,
String board, String bootloader, String hardware, String id,
String product, String serial, Date activationDate,
Date lastUpdatedDate, int deviceStatus) {
super();
this.deviceUniqueIdentity = deviceUniqueIdentity;
this.networkMacID = networkMacID;
this.model = model;
this.manufacturer = manufacturer;
this.androidVersion = androidVersion;
this.firstTimeInstalledDate = firstTimeInstalledDate;
this.buildID = buildID;
this.fingerPrint = fingerPrint;
this.board = board;
this.bootloader = bootloader;
this.hardware = hardware;
this.id = id;
this.product = product;
this.serial = serial;
this.activationDate = activationDate;
this.lastUpdatedDate = lastUpdatedDate;
this.rowStatus = deviceStatus;
}
@Override
public void setDeviceUniqueIdentity(String newDeviceUniqueIdentity) {
deviceUniqueIdentity = newDeviceUniqueIdentity;
}
@Override
public String getDeviceUniqueIdentity() {
return deviceUniqueIdentity;
}
public Date getFirstTimeInstalledDate() {
return firstTimeInstalledDate;
}
public void setFirstTimeInstalledDate(Date firstTimeInstalledDate) {
this.firstTimeInstalledDate = firstTimeInstalledDate;
}
public String getNetworkMacID() {
return networkMacID;
}
public void setNetworkMacID(String networkMacID) {
this.networkMacID = networkMacID;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getAndroidVersion() {
return androidVersion;
}
public void setAndroidVersion(String androidVersion) {
this.androidVersion = androidVersion;
}
public String getBuildID() {
return buildID;
}
public void setBuildID(String buildID) {
this.buildID = buildID;
}
public String getFingerPrint() {
return fingerPrint;
}
public void setFingerPrint(String fingerPrint) {
this.fingerPrint = fingerPrint;
}
public Date getActivationDate() {
return activationDate;
}
public void setActivationDate(Date activationDate) {
this.activationDate = activationDate;
}
public Date getLastUpdatedDate() {
return lastUpdatedDate;
}
public void setLastUpdatedDate(Date lastUpdatedDate) {
this.lastUpdatedDate = lastUpdatedDate;
}
public int getRowStatus() {
return rowStatus;
}
public void setRowStatus(int rowStatus) {
this.rowStatus = rowStatus;
}
public String getBoard() {
return board;
}
public void setBoard(String board) {
this.board = board;
}
public String getBootloader() {
return bootloader;
}
public void setBootloader(String bootloader) {
this.bootloader = bootloader;
}
public String getHardware() {
return hardware;
} +------------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+--------------+------+-----+---------+-------+
| deviceUniqueIdentity | varchar(50) | NO | PRI | NULL | |
| networkMacID | varchar(40) | YES | | NULL | |
| model | varchar(45) | YES | | NULL | |
| manufacturer | varchar(45) | YES | | NULL | |
| androidVersion | varchar(45) | YES | | NULL | |
| buildID | varchar(45) | YES | | NULL | |
| fingerPrint | varchar(100) | YES | | NULL | |
| activationDate | datetime | YES | | NULL | |
| lastUpdatedDate | datetime | YES | | NULL | |
| rowStatus | int(11) | YES | | NULL | |
| board | varchar(45) | YES | | NULL | |
| bootloader | varchar(45) | YES | | NULL | |
| hardware | varchar(45) | YES | | NULL | |
| id | varchar(45) | YES | | NULL | |
| product | varchar(45) | YES | | NULL | |
| serial | varchar(45) | YES | | NULL | |
| firstTimeInstalledDate | datetime | YES | | NULL | |
+------------------------+--------------+------+-----+---------+-------+
public void setHardware(String hardware) {
this.hardware = hardware;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getProduct() {
return product;
}
public void setProduct(String product) {
this.product = product;
}
public String getSerial() {
return serial;
}
public void setSerial(String serial) {
this.serial = serial;
}
public String constructAuthenticationSeed() {
return getNetworkMacID();
}
}
** **的hbm.xml com.mycompany.common.contracts.CDeviceDetails
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<!-- Generated 9 Jun, 2010 11:14:41 PM by Hibernate Tools 3.3.0.GA -->
<hibernate-mapping>
<class name="com.mycompany.common.contracts.CDeviceDetails" table="deviceDetails">
<id name="deviceUniqueIdentity" type="java.lang.String">
<column name="deviceUniqueIdentity" />
<generator class="assigned" />
</id>
<property name="networkMacID" type="java.lang.String">
<column name="networkMacID" />
</property>
<property name="model" type="java.lang.String">
<column name="model" />
</property>
<property name="manufacturer" type="java.lang.String">
<column name="manufacturer" />
</property>
<property name="androidVersion" type="java.lang.String">
<column name="androidVersion" />
</property>
<property name="buildID" type="java.lang.String">
<column name="buildID" />
</property>
<property name="fingerPrint" type="java.lang.String">
<column name="fingerPrint" />
</property>
<property name="activationDate" type="java.util.Date">
<column name="activationDate" />
</property>
<property name="lastUpdatedDate" type="java.util.Date">
<column name="lastUpdatedDate" />
</property>
<property name="rowStatus" type="java.lang.Integer">
<column name="rowStatus" />
</property>
<property name="board" type="java.lang.String">
<column name="board" />
</property>
<property name="bootloader" type="java.lang.String">
<column name="bootloader" />
</property>
<property name="hardware" type="java.lang.String">
<column name="hardware" />
</property>
<property name="id" type="java.lang.String">
<column name="id" />
</property>
<property name="product" type="java.lang.String">
<column name="product" />
</property>
<property name="serial" type="java.lang.String">
<column name="serial" />
</property>
<property name="firstTimeInstalledDate" type="java.util.Date">
<column name="firstTimeInstalledDate" />
</property>
</class>
</hibernate-mapping>
Mysql描述deviceDetails
的MySQL&GT;描述deviceDetails;
+------------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+--------------+------+-----+---------+-------+
| deviceUniqueIdentity | varchar(50) | NO | PRI | NULL | |
| networkMacID | varchar(40) | YES | | NULL | |
| model | varchar(45) | YES | | NULL | |
| manufacturer | varchar(45) | YES | | NULL | |
| androidVersion | varchar(45) | YES | | NULL | |
| buildID | varchar(45) | YES | | NULL | |
| fingerPrint | varchar(100) | YES | | NULL | |
| activationDate | datetime | YES | | NULL | |
| lastUpdatedDate | datetime | YES | | NULL | |
| rowStatus | int(11) | YES | | NULL | |
| board | varchar(45) | YES | | NULL | |
| bootloader | varchar(45) | YES | | NULL | |
| hardware | varchar(45) | YES | | NULL | |
| id | varchar(45) | YES | | NULL | |
| product | varchar(45) | YES | | NULL | |
| serial | varchar(45) | YES | | NULL | |
| firstTimeInstalledDate | datetime | YES | | NULL | |
+------------------------+--------------+------+-----+---------+-------+
异常
org.hibernate.MappingException: Unknown entity: com.mycompany.backend.hibernate.DeviceDetails
at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1096)
答案 0 :(得分:1)
您正在尝试保存类com.mycompany.backend.hibernate.DeviceDetails
的实体,同时在hibernate映射配置中定义类型为com.mycompany.common.contracts.CDeviceDetails
的实体。
因此,Hibernate不知道您提供的实体,也无法执行任何操作。