Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp
i created a .sar file to deploy hibernate service as MBean in jboss. I have included the persistant class as well as mapping file along with that. The service is successfull nut i am getting LazyInitializationException when i call openSession() method.
Hibernate version: 2
Mapping documents:
FOR CLASS EVENT
--------------------------
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN" "hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<class name="de.gloegl.road2hibernate.Event" table="EVENTS" dynamic-update="true">
<id name="id" column="uid" type="long">
<generator class="net.sf.hibernate.id.SequenceGenerator"/>
</id>
<property name="title" column="eventtitle" type="string" />
<property name="date" column="date" type="timestamp" />
<set name="participatingUsers" table="participations">
<key column="event_uid"/>
<many-to-many column="user_uid" class="de.gloegl.road2hibernate.User"/>
</set>
</class>
</hibernate-mapping>
FOR CLASS USER
-----------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="de.gloegl.road2hibernate.User" table="USERS">
<id name="id" column="uid" type="long">
<generator class="net.sf.hibernate.id.SequenceGenerator"/>
</id>
<property name="age"/>
<property name="firstName"/>
<property name="lastName"/>
<set name="favouriteEvents" table="favourite_events">
<key column="user_id" />
<many-to-many column="event_uid" class="de.gloegl.road2hibernate.Event"/>
</set>
<set name="emails" table="user_emails">
<key column="user_uid"/>
<element column="email" type="string"/>
</set>
<set name="eventsJoined" table="participations" inverse="true">
<key column="user_uid"/>
<many-to-many column="event_uid" class="de.gloegl.road2hibernate.Event"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
try{
Properties p=new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
p.put(Context.PROVIDER_URL,"jnp://localhost:1099");
Context ctx=new InitialContext(p);
//javax.sql.DataSource ds=(javax.sql.DataSource)ctx.lookup("java:/GossipDS");
net.sf.hibernate.SessionFactory sf=(net.sf.hibernate.SessionFactory)ctx.lookup("java:/hibernate/GossipHibernate");
//System.out.println("is lazy -- "+sf.getCollectionMetadata("").isLazy());
if(sf==null)
System.out.println("Got PROBS");
else
System.out.println("OK Fine");
net.sf.hibernate.Session session=sf.openSession(); //HERE IS THE ERROR
//net.sf.hibernate.Transaction transaction=session.beginTransaction();
//System.out.println("Transaction :"+transaction);
System.out.println("Inside SS :"+sf);
}catch(Exception e){
//e.printStackTrace();
System.out.println("Error in LookUP :"+e);
// e.printStackTrace();
}
Full stack trace of any exception that occurs:
Name and version of the database you are using:
Postgres 7.4.5
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
A simple java class calls the Session Ejb , which contains a method that lookups the sessionFactory
on line sessionFactory.getSession()
the following error is shown is JBoss console (ie, before session is created and after the session factory lookup)
INFO [STDOUT] Error in Lookup : net.sf.hibernate.LazyInitializationException : Hibernate lazy instantiation problem
HOW could i get such an exception when openSession() is called...
PLzzzzzzzz help