Brad Ko

Greenhorn
+ Follow
since Jul 27, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Brad Ko

Thanks Edvins

The issue has been solved with your idea.
UserTransaction is taken from Session bean (BMP) and it sets transaction scope in session bean method which calls Hibernate DAO class. The method of the DAO class updates data into multiple data source. It works fine (even I don�t do performance testing yet).

Here is hibernate configuration and EJB method for another people who try to find out a example code of distributed transaction management.



==EJB method (BMP)===
Here you are.

0000002e SystemErr R 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:544)
at com.ibm.msp.webtim.hibernate.InitSessionFactory.getCurrentSession(InitSessionFactory.java:87)
at com.ibm.msp.webtim.dao.TestORDao.updateTestOR(TestORDao.java:59)
at webtest.actions.FirstAction.execute(FirstAction.java:37)
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:1482)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1212)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:629)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:2837)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:220)
at com.ibm.ws.webcontainer.VirtualHost.handleRequest(VirtualHost.java:204)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:1681)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:77)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:421)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:367)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminaters(NewConnectionInitialReadCallback.java:201)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:103)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:548)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:601)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:934)
at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1021)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java(Compiled Code))
Caused by: org.hibernate.HibernateException: java.lang.reflect.InvocationTargetException
at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter.registerSynchronization(WebSphereExtendedJTATransactionLookup.java:165)
at org.hibernate.transaction.CMTTransaction.registerSynchronization(CMTTransaction.java:156)
... 28 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java(Compiled Code))
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java(Compiled Code))
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at org.hibernate.transaction.WebSphereExtendedJTATransactionLookup$TransactionManagerAdapter$TransactionAdapter.registerSynchronization(WebSphereExtendedJTATransactionLookup.java:159)
... 29 more
Caused by: com.ibm.websphere.jtaextensions.NotSupportedException
at com.ibm.ws.jtaextensions.ExtendedJTATransactionImpl.registerSynchronizationCallbackForCurrentTran(ExtendedJTATransactionImpl.java:227)
... 35 more
If I use �JTATransactionFactory� in hibernate configuration, this error message is shown.
�org.hibernate.TransactionException: could not register synchronization with JTA TransactionManager�

<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JTATransactionFactory
</property>
<property name="hibernate.transaction.manager_lookup_class">
org.hibernate.transaction.WebSphereExtendedJTATransactionLookup
</property>
Hi Edvins

Thanks for your quick answer and valuable information. Someone suggested me using distributed transaction manager with the XA version of JDBC driver and I tried to implement it, however I got a error message
�org.hibernate.TransactionException: could not register synchronization�.
Would you correct me what I am wrong from the following?

Thanks again,
Brad

===Oracle(9i) JDBC Driver (XA) on Websphere(v6.1) datasource===
oracle.jdbc.xa.client.OracleXADataSource

===hibernate(v3.2.5.ga) configuration===
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle9iDialect</property>
<property name="hibernate.connection.datasource">jdbc/dsXA1</property>

<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.CMTTransactionFactory
</property>
<property name="hibernate.transaction.manager_lookup_class">
org.hibernate.transaction.WebSphereExtendedJTATransactionLookup
</property>

<property name="show_sql">true</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
</session-factory>
</hibernate-configuration>

[Java(v1.4) dao code]
for (int idx=0; idx<InitSessionFactory.NUMBER_OF_INSTATNCE; idx++)
{
try
{
Session session = InitSessionFactory.getCurrentSession(idx);
session.saveOrUpdate(obj);
}
catch ( Exception e )
{
e.printStackTrace();
log.error(": Exception on <updateTestOR>: " + e.getMessage());
}
}
It can be configured as this topic multiple DB connections using hibernate

But it doesn't include how to manage transactions.
[ January 16, 2008: Message edited by: Brad Ko ]
Hi,

If you want to manage transactions on multiple databases connections, can you do that with Hibernate?

For instance, I want to update data on both databases, but the first transaction on a DB has to be rollback after second transaction on the other DB fails. How can you handle this kind scenario?

Thanks in advance.
Brad
Hi,

If you want to manage transaction for all databases, can you do that with Hibernate?

For instance, I want to update data on both databases, but the first transaction on a DB has to be rollback after second transaction on the other DB fails. How can you handle this kind scenario?

Thanks in advance.

Brad
[ January 15, 2008: Message edited by: Brad Ko ]
Nobody can answer for this question?
Does anyone know what methods I can use to remove and redefine the default namespace? I'm using xmlbeans(v2.2.0).

For our project, I want to redefine the namespace on the orignal xml to look like the target xml (see XML examples below).

=====Orignal XML=====
<ClientData xmlns="http://www.company.com">
<customerInformation>
<accessCard>
<accessCardNumber>45xxxxxxxxxx99</accessCardNumber>
</accessCard>
</customerInformation>
<w3:Info xmlns="http://company.org/schemas" xmlns:w3="http://www.company.com">
<w3:Count>6</w3:Count>
<w3:AddDataFlag>N</w3:AddDataFlag>
<w3:VendorList>
<w3:PayeeID>00001</w3:PayeeID>
<w3:PayeeTkn>###123456</w3:PayeeTkn>
<w3:PayeeName>AAAAAAA</w3:PayeeName>
<w3:CustPayeeID>00000</w3:CustPayeeID>
<w3:PayeeDataType/>
<w3:PayeeData/>
</w3:VendorList>
</w3:Info>
</ClientData>

====Target XML=====
<ClientData xmlns="http://www.company.com">
<customerInformation>
<accessCard>
<accessCardNumber>45xxxxxxxxxx99</accessCardNumber>
</accessCard>
</customerInformation>
<Info>
<Count>6</Count>
<AddDataFlag>N</AddDataFlag>
<VendorList>
<PayeeID>00001</PayeeID>
<PayeeTkn>###123456</PayeeTkn>
<PayeeName>AAAAAAA</PayeeName>
<CustPayeeID>00000</CustPayeeID>
<PayeeDataType/>
<PayeeData/>
</VendorList>
</Info>
</ClientData>

Thanks in advance.