Hi All
I'm new with hibernate, I had following problem working with hibernate
Hibernate version: 3.2
Mapping documents:
<class name="com.arkalogic.parkalogic.ejb.pojo.User" table="tbluser"> <id name="userid" column="user_id" type="integer"><generator class="native"/></id> <property name="fullname" type="string"/> <many-to-one name="typeshift" column="type_shift" class="com.arkalogic.parkalogic.ejb.pojo.UserShift" cascade="save-update" /> </class>
<class name="com.arkalogic.parkalogic.ejb.pojo.UserShift" table="user_shift"> <id name="id" column="gid" type="integer"><generator class="native"/></id> <property name="shiftname" column="shift_name" type="string"/> <property name="desc" column="description" type="string"/> </class>
Code between sessionFactory.openSession() and session.close():
This is hibernate dao in my ejb
public User getUser(String username) { User user = null; try { HibernateUtil.beginTransaction(); Session sess = HibernateUtil.getSession(); Query query = sess.createQuery("from User where username = :username").setString("username", username); System.out.println("user query has next: " + query.iterate().hasNext()); user = (User) query.iterate().next(); if(user != null){ System.out.println("user fullname: " + user.getFullname()); }else{ System.out.println("user null"); } } catch (Exception e) { HibernateUtil.rollbackTransaction(); e.printStackTrace(); } return user; }
Full stack trace of any exception that occurs:
when I call getUser from ejb client, got the following expcetion
SEVERE: could not initialize proxy - no Session org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111) at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:172) at com.arkalogic.parkalogic.ejb.pojo.UserShift$$EnhancerByCGLIB$$d2e6d969.getDesc(<generated>) at helloclient.Main.testClient(Main.java:154) at helloclient.Main.main(Main.java:68) org.hibernate.LazyInitializationException: could not initialize proxy - no Session at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57) at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111) at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:172) at com.arkalogic.parkalogic.ejb.pojo.UserShift$$EnhancerByCGLIB$$d2e6d969.getDesc(<generated>) at helloclient.Main.testClient(Main.java:154) at helloclient.Main.main(Main.java:68)
While the code snippet ib my client is :
AdminFacadeRemote afs = (AdminFacadeRemote) lookupbeanAdmin().create(AppConfig.ADMINUSER); AdminFacadeRemote afsa = (AdminFacadeRemote) lookupbeanAdmin().create(AppConfig.ADMINUSERSHIFT); User u = (User) afs.getUser("admin"); System.out.println(u.getFullname()); System.out.println(u.getTypeshift().getDesc()); // this is line 154
Name and version of the database you are using:
I'm using mysql version 4.1.13
The generated SQL (show_sql=true):
The generated sql in my ejb server as a follow
[#|2006-12-07T15:16:47.335+0700|INFO|sun-appserver-pe9.0|javax.enterprise.system.stream.out|_ThreadID=15;_ThreadName=p: thread-pool-1; w: 7;| Hibernate: select user0_.user_id as col_0_0_ from tbluser user0_ where user0_.username=?|#]
[#|2006-12-07T15:16:47.362+0700|INFO|sun-appserver-pe9.0|javax.enterprise.system.stream.out|_ThreadID=15;_ThreadName=p: thread-pool-1; w: 7;| Hibernate: select user0_.user_id as col_0_0_ from tbluser user0_ where user0_.username=?|#]
[#|2006-12-07T15:16:47.381+0700|INFO|sun-appserver-pe9.0|javax.enterprise.system.stream.out|_ThreadID=15;_ThreadName=p: thread-pool-1; w: 7;| Hibernate: select user0_.user_id as user1_0_0_, user0_.username as username0_0_, user0_.password as password0_0_, user0_.user_level as user4_0_0_, user0_.blocked_state as blocked5_0_0_, user0_.login_state as login6_0_0_, user0_.employee_id as employee7_0_0_, user0_.login_time as login8_0_0_, user0_.logout_time as logout9_0_0_, user0_.fullname as fullname0_0_, user0_.type_shift as type11_0_0_, user0_.user_group as user12_0_0_ from tbluser user0_ where user0_.user_id=?|#]
seems that UserShift query is not there
Kindly please enlight me how to solve this
|