Neer1009
Neer1009

Reputation: 314

ERROR: No such column name.INFO: HHH000327: Error performing load command : org.hibernate.exception.GenericJDBCException:

I just created a simple Java project. I am able to persist the object successfully, but when I try to retrieve it, it throws an error:

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]

My code for Entity class is :

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

Test class for testing hibernate is:

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 which is being used to create the table is:

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

Upvotes: 0

Views: 15648

Answers (1)

akash777.sharma
akash777.sharma

Reputation: 702

Hibernate has this bug which is similar to your problem.

Remove parameter DELIMIDENT=y from the datasource URL.

Generally HHH000327 this error comes when you have some error in naming column in tables. So you can try to name columns with @Column annotation. Be sure that you are not using any database specific constant , like User is already defined constant in postgres.

Upvotes: 1

Related Questions