I was practicing a sample of hibernate to fetch data .I was encountered with an exception
INFO: HHH000327: Error performing load command : org.hibernate.HibernateException: Javassist Enhancement failed: com.practice.hibernate.Customer
Exception in thread "main" org.hibernate.HibernateException: Javassist Enhancement failed: com.practice.hibernate.Customer
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:142)
Solution :
Please make sure that if you're overloading constructor in a class make a presence of actual empty argument constructor in it
in my case
Customer.java looks like
INFO: HHH000327: Error performing load command : org.hibernate.HibernateException: Javassist Enhancement failed: com.practice.hibernate.Customer
Exception in thread "main" org.hibernate.HibernateException: Javassist Enhancement failed: com.practice.hibernate.Customer
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:142)
Solution :
Please make sure that if you're overloading constructor in a class make a presence of actual empty argument constructor in it
in my case
Customer.java looks like
package com.practice.hibernate;
public class Customer {
private int cid;
private String name;
private String city;
private long phone;
private double balance;
public Customer(String name,String city,long phone,double balance) {
this.name=name;
this.city=city;
this.phone=phone;
this.balance=balance;
}
public int getCid() {
return cid;
}
public void setCid(int cid) {
this.cid = cid;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public long getPhone() {
return phone;
}
public void setPhone(long phone) {
this.phone = phone;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
To avoid the Exception i have modified the class a below
package com.practice.hibernate;
public class Customer {
private int cid;
private String name;
private String city;
private long phone;
private double balance;
public Customer() {
// TODO Auto-generated constructor stub
}
public Customer(String name,String city,long phone,double balance) {
// TODO Auto-generated constructor stub
this.name=name;
this.city=city;
this.phone=phone;
this.balance=balance;
}
public int getCid() {
return cid;
}
public void setCid(int cid) {
this.cid = cid;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public long getPhone() {
return phone;
}
public void setPhone(long phone) {
this.phone = phone;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
No comments:
Post a Comment