Hi,
i'm trying to build my first hibernate app, but i'm also having problems.
I'm on JBoss 3.2.3 and Hibernate 2.1.
Is the file Hibernate.cfg.xml always needed? If it is, where should i include it?
I followed the "tutorial" at the site to use hibernate as an mbean in jboss,
so doesn't the jboss-service.xml do the whole service?
I'm getting an exception when trying to access the db and i don't know if it has something to do with the hibernate.cfg.file.
My exception is
10:18:42,921 INFO [STDOUT] Found jndi ok !!!
10:18:42,921 INFO [HibernateServiceMBean] starting service at JNDI name: java:/hibernate/SessionFactory
10:18:42,921 INFO [HibernateServiceMBean] service properties: {hibernate.session_factory_name=java:/hibernate/SessionFactory, hibernate.transaction.manager_lookup_class=net.sf.hibernate.transaction.JBossTransactionManagerLookup, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.show_sql=false, hibernate.use_outer_join=false, hibernate.transaction.factory_class=net.sf.hibernate.transaction.JTATransactionFactory, hibernate.connection.datasource=java:comp/env/jdbc/hibernate_test, jta.UserTransaction=UserTransaction}
10:18:42,921 INFO [Configuration] Mapping resource: hibernate/Person.hbm.xml
10:18:42,921 ERROR [LogInterceptor] RuntimeException:
net.sf.hibernate.LazyInitializationException: Hibernate lazy instantiation problem
For the following Session bean code
Code:
Context ctx = new InitialContext();
SessionFactory factory = (SessionFactory) ctx.lookup("java:/hibernate/SessionFactory");
if (factory == null){
System.out.println("Lookup returned NULL !!!");
}
System.out.println("Found jndi ok !!! ");
Session session = factory.openSession();
System.out.println("Opened session ok !!! ");
My jboss-service.xml is the following
Code:
<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=Hibernate">
<depends>jboss.jca:service=RARDeployer</depends>
<attribute name="MapResources">hibernate/Person.hbm.xml</attribute>
<attribute name="JndiName">java:/hibernate/SessionFactory</attribute>
<attribute name="Datasource">java:comp/env/jdbc/hibernate_test</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
<attribute name="UseOuterJoin">false</attribute>
<attribute name="ShowSql">false</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
</mbean>
</server>
Thanks a lot,
ltcmelo