Hazi pasha.MD wrote:
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelpHibernate version: Mapping documents:Code between sessionFactory.openSession() and session.close():Full stack trace of any exception that occurs:Name and version of the database you are using:The generated SQL (show_sql=true):Debug level Hibernate log excerpt:Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html
06/10/31 15:06:40 Excep raised in DAOCould not locate TransactionManager
org.hibernate.HibernateException: Could not locate TransactionManager
at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:26)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:302)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
at SpryIndia.com.DAO.store(DAO.java:27)
at SpryIndia.com.Session1Bean.storeDetails(Session1Bean.java:53)
at Session1_StatelessSessionBeanWrapper0.storeDetails(Session1_StatelessSessionBeanWrapper0.java:96)
at SpryIndia.com.Model.storeDetails(Model.java:25)
at SpryIndia.com.Action1.execute(Action1.java:28)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1485)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:527)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
at oracle.security.jazn.oc4j.JAZNFilter.doFilter(Unknown Source)
at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:649)
at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:322)
at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:790)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:270)
at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:112)
at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
at java.lang.Thread.run(Thread.java:534)
Caused by: javax.naming.NameNotFoundException: Only session and message-driven beans with bean-managed transaction are allowed to use UserTransaction
at com.evermind.server.ApplicationContext.lookupJavaCompRsrc(ApplicationContext.java:180)
at com.evermind.server.ApplicationContext.lookupJavaComp(ApplicationContext.java:136)
at com.evermind.server.ApplicationContext.lookup(ApplicationContext.java:306)
at com.evermind.server.ApplicationContext.lookup(ApplicationContext.java:120)
at javax.naming.InitialContext.lookup(InitialContext.java:347)
at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:23)
... 22 more
06/10/31 15:06:40 4
-- DEBUG -- processForwardConfig(ForwardConfig[name=success,path=/success.jsp,redirect=false,contextRelative=false])
Configuration conf=new Configuration();
conf.configure();
org.hibernate.SessionFactory sf=conf.buildSessionFactory();
org.hibernate.Session ses= sf.getCurrentSession();
Transaction tx=ses.beginTransaction();
System.out.println("DAO finish");
System.out.println(spry.getRecNo());
System.out.println(spry.getRole_Id());
ses.save(spry);
ses.getTransaction().commit();
}
catch(Exception e)
{
System.out.println("Excep raised in DAO"+e.getMessage());
e.printStackTrace();
}
}
}
<hibernate-configuration>
<session-factory name="java:comp/env/hibernate/SessionFactory">
<property name="hibernate.generate_statistics">true</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.use_sql_comments">true</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.order_updates">true</property>
<property name="connection.datasource">jdbc/testDS</property>
<property name="hibernate.connection.username">spry</property>
<property name="hibernate.connection.password">spry</property>
<property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.OrionTransactionManagerLookup</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.current_session_context_class">jta</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.transaction.auto_close_session">true</property>
<property name="hibernate.connection.release_mode">auto</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
<mapping resource="Spry.hbm.xml"/>
</session-factory>
</hibernate-configuration>
mapping file
<hibernate-mapping>
<class name="SpryIndia.com.Spry" table="spry">
<id name="recNo" type="java.lang.String" column="RECNO" >
<generator class="assigned"/>
</id>
<property name="role_Id">
<column name="ROLE_ID" />
</property>
</class>
</hibernate-mapping>