gpt4 book ai didi

java - 错误: No such column name.信息: HHH000327: Error performing load command : org. hibernate.exception.GenericJDBCException:

转载 作者:行者123 更新时间:2023-12-01 10:38:03 25 4
gpt4 key购买 nike

我刚刚创建了一个简单的 Java 项目。我能够成功地持久化该对象,但是当我尝试检索它时,它会抛出一个错误:

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;
}
}

用于测试hibernate的测试类是:

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

Stack Trace for error in eclipse console

最佳答案

Hibernate 有这个 bug这与您的问题类似。

从数据源 URL 中删除参数 DELIPIDENT=y。

通常HHH000327当您在表中命名列时出现一些错误时,就会出现此错误。因此,您可以尝试使用 @Column 注解来命名列。确保您没有使用任何数据库特定常量,例如 User 已在 postgres 中定义常量。

关于java - 错误: No such column name.信息: HHH000327: Error performing load command : org. hibernate.exception.GenericJDBCException:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34565915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com