我剛創建了一個簡單的Java項目。我能夠成功地堅持了對象,但是當我試圖找回它,它拋出一個錯誤:錯誤:No such column name.INFO:HHH000327:執行加載命令時出錯:org.hibernate.exception.GenericJDBCException:
ERROR: No such column name Jan 02, 2016 5:44:05 PM org.hibernate.event.internal.DefaultLoadEventListener onLoad INFO: HHH000327: Error performing load command : org.hibernate.exception.GenericJDBCException: Could not read entity state from ResultSet : EntityKey[org.neeraj.walmart.dto.UserDetails#1]
我的實體類代碼是:測試休眠
package org.neeraj.walmart.dto;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
@Entity
public class UserDetails {
@Id
private int userNewid;
private String userName;
private Date joinedDate;
private String Address;
private String description;
public int getUserId() {
return userNewid;
}
public void setUserId(int userId) {
this.userNewid = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public Date getJoinedDate() {
return joinedDate;
}
public void setJoinedDate(Date joinedDate) {
this.joinedDate = joinedDate;
}
public String getAddress() {
return Address;
}
public void setAddress(String address) {
Address = address;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
測試類:這被用來創建該表
package org.neeraj.walmart;
import java.util.Date;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.RollbackException;
import org.neeraj.walmart.dto.UserDetails;
public class HibernateTest {
public static void main(String[] args) {
UserDetails user1 = new UserDetails();
user1.setUserId(1);
user1.setUserName("First User");
user1.setJoinedDate(new Date());
user1.setAddress("User1 address");
user1.setDescription("User1 description is present here");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("HibernateLearningContext");
//Code snippet to save the object to DB
EntityManager em = emf.createEntityManager();
try {
em.getTransaction().begin();
em.persist(user1);
em.getTransaction().commit();
} catch (RollbackException ex) {
em.getTransaction().rollback();
} finally {
em.close();
}
// code snippet to retrieve the object
UserDetails user1Copy = null;
em = emf.createEntityManager();
try {
em.getTransaction().begin();
user1Copy = em.find(UserDetails.class, 1); // This method finds by primary key
if (user1Copy == null) {
System.out.println(" data not found");
} else {
System.out.println("user name retrived is " + user1Copy.getUserName());
}
} catch (Exception ex) {
} finally {
em.close();
}
}
}
DDL是:
CREATE TABLE userdetails (
userNewid INTEGER NOT NULL,
address VARCHAR(255),
description VARCHAR(255),
joineddate DATETIME,
username VARCHAR(255),
CONSTRAINT u177_235 PRIMARY KEY (userNewid)
);
你的餐桌喜歡什麼? – SMA
表DDL看起來像這樣: - CREATE TABLE出站:gls.user_details( \t userNewid INTEGER NOT NULL, \t地址VARCHAR(255), \t描述VARCHAR(255), \t joineddate DATE, \t用戶名VARCHAR(255 ), \t CONSTRAINT u160_201 PRIMARY KEY(userNewid) );這個我從Dbeaver DDL複製 – Neer1009
@SMA是你正在尋找的這個表結構還是其他的東西? – Neer1009