-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: getCurrentSession Hibernate+Struts+Websphere
PostPosted: Fri Dec 16, 2005 9:49 am 
Newbie

Joined: Fri Dec 16, 2005 5:07 am
Posts: 6
my environment is websphere 5.1+struts+hibernate 3.1. I would like to use only getCurrentSession function in CMT. (no transaction and session closing)
For this i should configure following parameters in hibernate.cfg.xml

<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.transaction.auto_close_session">true</property>

And i would like to ask if someone could explain me what should be in following properties
transaction.factory_class, transaction.manager_lookup_class

if i set it to
<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.WebSphereTransactionManagerLookup</property>

what i understand than JTATransationFactory is more generous than CMPTransactionFactory
i got in getCurrentSession() -> org.hibernate.HibernateException: Unable to locate current JTA transaction

when is use it without these parameters, and use getCurrentSession i got
"org.hibernate.HibernateException: No CurrentSessionContext configured!"
but i am able to get session using openSession but then i have to use session.beginTransaction to update my data

I miss something but don't see the key

enclosed hibernate.cfg.xml
<session-factory>

<!-- Data Source -->
<property name="connection.datasource">java:comp/env/jdbc/dzos</property>

<!-- Database Settings -->
<property name="default_schema">authadmin</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="show_sql">true</property>

<!-- JDBC Settings -->
<property name="jdbc.use_streams_for_binary">true</property>
<property name="max_fetch_depth">1</property>

<!-- Cache settings -->
<property name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>

<!-- Transaction API -->
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.transaction.auto_close_session">true</property>

<!-- Mapping files -->
<mapping resource="org/tesco/dzos/sql/Apcdval.hbm.xml"/>

</session-factory>


[Unable to locate current JTA transaction]: org.hibernate.HibernateException: Unable to locate current JTA transaction
[16.12.05 14:46:39:494 SEC] 2f8a5b4b WebGroup E SRVE0026E: [Servlet Error]-[Unable to locate current JTA transaction]: org.hibernate.HibernateException: Unable to locate current JTA transaction
at org.hibernate.context.JTASessionContext.currentSession(JTASessionContext.java:61)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:506)
at org.volsax.struts.HiberUtil.open(HiberUtil.java:84)
at org.tesco.dzos.struts.CdValAction.editA(CdValAction.java:251)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:276)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:196)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:983)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:564)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:200)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:119)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:276)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:618)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:439)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:672)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 17, 2005 12:12 am 
Beginner
Beginner

Joined: Thu Dec 01, 2005 7:07 pm
Posts: 21
Answers are there in Hibernate Reference pdf. When to use lookup_class
1) The classname of a TransactionManagerLookup - required
when JVM-level caching is enabled or when
using hilo generator in a JTA environment.
eg. classname.of.TransactionManagerLookup
2) When Hibernate is using
an application server datasource to obtain connections enlisted with JTA
3) Note that you should choose org.hibernate.transaction.JTATransactionFactory in a BMT session bean,
and org.hibernate.transaction.CMTTransactionFactory in a CMT session bean, when you configure Hibernate's
transaction factory. Remember to also set org.hibernate.transaction.manager_lookup_class.

If you are using Websphere, you should be using CMTtransactionFactory and also an extended lookup for Websphere.
"org.hibernate.transaction.WebSphereTransactionManagerLookup for WebSphere
org.hibernate.transaction.WebSphereExtendedJTATransactionLookup for WebSphere 6"

Confgure a datasource connection thru app server and use the same. Transaction management to be left to the app server (in case of CMT)

Take care


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 17, 2005 7:59 pm 
Newbie

Joined: Fri Dec 16, 2005 5:07 am
Posts: 6
i changed configuration file to

<property name="current_session_context_class">thread</property>
<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.transaction.auto_close_session">true</property>
<property name="transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.WebSphereTransactionManagerLookup</property>

but now i am geting "Could not register synchronization"
E SRVE0026E: [Servlet Error]-[Could not register synchronization]: org.hibernate.TransactionException: Could not register synchronization
at org.hibernate.transaction.CMTTransaction.registerSynchronization(CMTTransaction.java:159)
at org.hibernate.context.ThreadLocalSessionContext.currentSession(ThreadLocalSessionContext.java:78)
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:506)

When i use openSession i get over it but every second call generate following exception

org.apache.struts.action.RequestProcessor Unhandled Exception thrown: class org.hibernate.PropertyAccessException
[18.12.05 0:51:56:859 SEČ] 2c280816 WebGroup E SRVE0026E: [Servlet Error]-[exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of org.tesco.dzos.sql.Apcdval.setLang]: org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of org.tesco.dzos.sql.Apcdval.setLang
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 org.tesco.dzos.struts.CdValAction.list(CdValAction.java:74)

how it is possible that first call is working and second generate exception.
any ideas ?!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 17, 2005 9:41 pm 
Newbie

Joined: Fri Dec 16, 2005 5:07 am
Posts: 6
the "org.hibernate.PropertyAccessException" was my fault i had one int value null.

to summarizate in CMT synchronization exception... and when JTATransactionFactory is used I can't use getCurrentSession, and then when i use openSession using hibernateUtils the data are not saved :-(

<property name="hibernate.transaction.flush_before_completion">true</property>
<property name="hibernate.transaction.auto_close_session">true</property>
<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.WebSphereTransactionManagerLookup</property>

Session dbf = HiberUtil.open();

Apcdval cd = new Apcdval();
cd.setCd_val(frm.getI("cd_val"));
cd.setTbl_cd(frm.getI("tbl_cd"));
cd.setSdsc(frm.getS("sdsc"));
cd.setLdsc(frm.getS("ldsc"));
cd.setRstat(frm.getI("rstat"));
cd.setLang(frm.getI("lang"));
cd.setRdt(new Date());

log.info("edit apcdval:" + frm.getValues());
dbf.saveOrUpdate(cd);

HiberUtil.close();

any ideas ?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 18, 2005 6:09 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://hibernate.org/42.html
http://hibernate.org/43.html


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 18, 2005 11:53 am 
Newbie

Joined: Fri Dec 16, 2005 5:07 am
Posts: 6
i have read the articles...ok ...

I switch on ContainerManged persistence (use this data source in container managed persistence) in Websphere console.

i set
<property name="transaction.manager_lookup_class">org.hibernate.transaction.WebSphereTransactionManagerLookup</property>
<property name="current_session_context_class">jta</property>
<property name="transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>

or (according reference manual is also possible to use it)
<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>

and got

org.hibernate.HibernateException: Unable to locate current JTA transaction

which is realy similar to same issue,
http://forum.hibernate.org/viewtopic.php?t=942973

there are couple things which are not clear
- how could i set CMT / BMT...is it only in hibernate.cfg.xml or also switch or something similar on websphere server ?
- there is something about type of transaction, getCurrentSession is not working when type "Supports", "Not Supported". Where i can set this type of transaction.

thanks for your time guys, i realy want to use it in my next project but can't get over


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.