Hi, I am new to hibernate project.Could you anybody please help me for the below issue.
If i try to fetch the data from table which has a foreign keys.I am getting the below issue and also problem is not exists for table with only primary key or without contain any entities.
Error: .......... WARNING: #{Scheduler.success1}: org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.verizonwirless.Dbmapping.UserDetail.setId javax.faces.FacesException: #{Scheduler.success1}: org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.verizonwirless.Dbmapping.UserDetail.setId at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118) at javax.faces.component.UICommand.broadcast(UICommand.java:315) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: javax.faces.el.EvaluationException: org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.verizonwirless.Dbmapping.UserDetail.setId at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) ... 26 more Caused by: org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.verizonwirless.Dbmapping.UserDetail.setId at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:215) at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:185) at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3232) at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:126) at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842) at org.hibernate.loader.Loader.doQuery(Loader.java:717) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) at org.hibernate.loader.Loader.doList(Loader.java:2150) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029) at org.hibernate.loader.Loader.list(Loader.java:2024) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:300) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:146) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1093) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79) at com.verizonwirless.Apppages.Scheduler.success1(Scheduler.java:66) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.el.parser.AstValue.invoke(AstValue.java:278) at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) ... 27 more Caused by: net.sf.cglib.beans.BulkBeanException: com.verizonwirless.Dbmapping.User$$EnhancerByCGLIB$$436d3027 cannot be cast to java.lang.Number at com.verizonwirless.Dbmapping.UserDetail$$BulkBeanByCGLIB$$59768799.setPropertyValues(<generated>) at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:212) ... 50 more Caused by: java.lang.ClassCastException: com.verizonwirless.Dbmapping.User$$EnhancerByCGLIB$$436d3027 cannot be cast to java.lang.Number ... 52 more
Dec 13, 2013 1:12:39 AM com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError SEVERE: javax.faces.el.EvaluationException: org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.verizonwirless.Dbmapping.UserDetail.setId at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101) at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) at javax.faces.component.UICommand.broadcast(UICommand.java:315) at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790) at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282) at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of com.verizonwirless.Dbmapping.UserDetail.setId at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:215) at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:185) at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3232) at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:126) at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842) at org.hibernate.loader.Loader.doQuery(Loader.java:717) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224) at org.hibernate.loader.Loader.doList(Loader.java:2150) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029) at org.hibernate.loader.Loader.list(Loader.java:2024) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:300) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:146) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1093) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79) at com.verizonwirless.Apppages.Scheduler.success1(Scheduler.java:66) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.el.parser.AstValue.invoke(AstValue.java:278) at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274) at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87) ... 27 more Caused by: net.sf.cglib.beans.BulkBeanException: com.verizonwirless.Dbmapping.User$$EnhancerByCGLIB$$436d3027 cannot be cast to java.lang.Number at com.verizonwirless.Dbmapping.UserDetail$$BulkBeanByCGLIB$$59768799.setPropertyValues(<generated>) at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:212) ... 50 more Caused by: java.lang.ClassCastException: com.verizonwirless.Dbmapping.User$$EnhancerByCGLIB$$436d3027 cannot be cast to java.lang.Number ... 52 more ................................................................
User.java class
import java.sql.Timestamp; import com.verizonwirless.Dbmapping.enumType.Good; public class User { public int id; public String name; public Timestamp date; public Good good; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Good getGood() { return good; } public void setGood(Good good) { this.good = good; } public Timestamp getDate() { return date; } public void setDate(Timestamp date) { this.date = date; }
} ................................. user detail class
public class UserDetail {
public int salary; public int id;
public int getSalary() { return salary; } public void setSalary(int salary) { this.salary = salary; } public int getId() { return id; } public void setId(int id) { this.id = id; } } .................................................... User.HBM.XML <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <class name="com.verizonwirless.Dbmapping.User" table="User"> <id name="id" type="int" column="ID"> <generator class="native" /> </id> <property name="Name" column="Name" length="10" type="string" not-null="true" /> <property name="Date" column="Date" type="timestamp" /> <property name="Good" column="Good"> <type name="org.hibernate.type.EnumType"> <param name="enumClass">com.verizonwirless.Dbmapping.enumType.Good</param> <param name="type">12</param> </type> </property> </class> </hibernate-mapping>
......................................
Userdetails.hbm.xml
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping> <class name="com.verizonwirless.Dbmapping.UserDetail" table="userdetail"> <id name="salary" type = "int" column="salary"> </id> <many-to-one class="com.verizonwirless.Dbmapping.User" name="id" column="id" not-null="true"/> </class> </hibernate-mapping>
Fetching Data query.... ....................................
import java.io.Serializable; import java.util.ArrayList; import java.util.List; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import com.verizonwirless.Dbmapping.enumType.ScheduleType;
@ManagedBean(name = "Scheduler") @SessionScoped public class Scheduler implements Serializable { /** * */ private static final long serialVersionUID = 1L;
//private static final ScheduleType scheduleType = "Immediate" ; private List<SchedulerObject> schedulerdata; public Session session; public Transaction tx; public SessionFactory sessionFactory; public ScheduleType scheduleType;
@SuppressWarnings({ "unused", "unchecked" }) public String success1(){ /*Properties params = new Properties(); params.put("enumClass", "Foo.ProfileStateEnum"); params.put("type", "12"); type 12 instructs to use the String representation of enum value Type myEnumType = new TypeLocatorImpl(new TypeResolver()).custom(EnumType.class, params);*/
System.out.println("IN SUCCESS"); System.out.println("IN"); /*java.util.Date date= new java.util.Date(); Timestamp a =new Timestamp(date.getTime()); schedulerdata=new ArrayList<SchedulerObject>(); SchedulerObject orderitem = new SchedulerObject(1,"1234" ,101,13282,ScheduleType.Scheduled, a,a,a); schedulerdata.add(orderitem); */ schedulerdata=new ArrayList<SchedulerObject>(); sessionFactory = new Configuration().configure("com\\verizonwirless\\xmlmappings\\hibernate.cfg.xml").buildSessionFactory(); session= sessionFactory.openSession(); System.out.println("hi"); tx=session.beginTransaction(); Query query = session.createQuery("from UserDetail"); System.out.println("out"); //System.out.println(query.getReturnTypes().toString()); System.out.println(query.list()); //schedulerdata=(List<SchedulerObject>) query.list(); System.out.println("List"); tx.commit(); session.close(); /* try{ sessionFactory = new Configuration().configure("com\\verizonwirless\\xmlmappings\\hibernate.cfg.xml").buildSessionFactory(); session= sessionFactory.openSession(); System.out.println("hi"); //schedulerdata=session.createQuery("from SchedulerDB").list(); String SQL_Query="FROM SchedulerDB";
Query query=session.createQuery(SQL_Query); List<?> Student=(List<?>) query.list(); Iterator<?> itr=((java.util.List<?>) Student).iterator(); System.out.println("TRANSACTION STARTED1112"); while(itr.hasNext()) { SchedulerDB emp=(SchedulerDB)itr.next(); System.out.println(emp.ApplicationID); } tx.commit(); }catch(HibernateException he){ if(tx!=null)tx.rollback(); he.printStackTrace(); }finally{ if(session!=null) session.close(); }*/ return "hi"; }
public List<SchedulerObject> getSchedulerdata() { //success1(); return this.schedulerdata; }
}
|