|
View:
New views
13 Messages
—
Rating Filter:
Alert me
|
|
|
Does jencks canbe integrated with hybernate?Hi,
Iam new to this jencks and even to hybernate. Just i want to know can i integrate jencks with hybernate. My requirement is there are 3 threads, 2 of them are hybernate session threads doing some DB operation and one more thread is using ActiveMQ. I want to make use of jenks for maintaing distributed transactions over these threads |
|
|
Re: Does jencks canbe integrated with hybernate?Transactions usually occur within a single thread, even when
distributed. You'd have to sequence your processing somehow... On 9/25/07, Arif Mohd <arif.mohammed1@...> wrote: > > Hi, > > Iam new to this jencks and even to hybernate. Just i want to know can i > integrate jencks with hybernate. My requirement is there are 3 threads, 2 of > them are hybernate session threads doing some DB operation and one more > thread is using ActiveMQ. I want to make use of jenks for maintaing > distributed transactions over these threads > -- > View this message in context: http://www.nabble.com/Does-jencks-canbe-integrated-with-hybernate--tf4514305.html#a12875825 > Sent from the jencks - user mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > -- Cheers, Guillaume Nodet ------------------------ Blog: http://gnodet.blogspot.com/ --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Does jencks canbe integrated with hybernate?Hi gnodet,
It will be a great help for me if you could help me with small code snippet. Iam entirely new to this technologies and iam trying to evaluate how i can make use of jencks. As you said iam having a controller entity which will be creating new threads(hybernate sessions) parallely and i want to make use of jencks here in controller entity for maintaining distributed transactions. Just help me how can i do stand alone setup for jencks(with out any app server stuff) with resource adapters.
|
|
|
Re: Does jencks canbe integrated with hybernate?I'm not sure what you are trying to do, but you can't expect a single
transaction to be splitted across different threads at the same time. You can find some example configurations using jencks in the source tree: http://svn.jencks.codehaus.org/browse/jencks/trunk/jencks/src/test/resources/org/jencks On 9/25/07, Arif Mohd <arif.mohammed1@...> wrote: > > Hi gnodet, > > It will be a great help for me if you could help me with small code > snippet. Iam entirely new to this technologies and iam trying to evaluate > how i can make use of jencks. > > As you said iam having a controller entity which will be creating new > threads(hybernate sessions) parallely and i want to make use of jencks here > in controller entity for maintaining distributed transactions. > > Just help me how can i do stand alone setup for jencks(with out any > app server stuff) with resource adapters. > > gnodet wrote: > > > > Transactions usually occur within a single thread, even when > > distributed. You'd have to sequence your processing somehow... > > > > On 9/25/07, Arif Mohd <arif.mohammed1@...> wrote: > >> > >> Hi, > >> > >> Iam new to this jencks and even to hybernate. Just i want to know can > >> i > >> integrate jencks with hybernate. My requirement is there are 3 threads, 2 > >> of > >> them are hybernate session threads doing some DB operation and one more > >> thread is using ActiveMQ. I want to make use of jenks for maintaing > >> distributed transactions over these threads > >> -- > >> View this message in context: > >> http://www.nabble.com/Does-jencks-canbe-integrated-with-hybernate--tf4514305.html#a12875825 > >> Sent from the jencks - user mailing list archive at Nabble.com. > >> > >> > >> --------------------------------------------------------------------- > >> To unsubscribe from this list please visit: > >> > >> http://xircles.codehaus.org/manage_email > >> > >> > > > > > > -- > > Cheers, > > Guillaume Nodet > > ------------------------ > > Blog: http://gnodet.blogspot.com/ > > > > --------------------------------------------------------------------- > > To unsubscribe from this list please visit: > > > > http://xircles.codehaus.org/manage_email > > > > > > > > -- > View this message in context: http://www.nabble.com/Does-jencks-canbe-integrated-with-hybernate--tf4514305.html#a12876311 > > Sent from the jencks - user mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > -- Cheers, Guillaume Nodet ------------------------ Blog: http://gnodet.blogspot.com/ --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Does jencks canbe integrated with hybernate?Hi gnodet,
Iam attaching my complete example(most of the configuration i took from one of the threads http://forum.springframework.org/showthread.php?t=32063) Please see that iam using sessionFactory.getCurrentSession() as it is said in the documentation this is used to associate a session object with JTATransaction(If JTA is enabled) My question is can i use session object like this across multiple threads, but it is said that session object is not thread safe(but here iam using JTATransaction) little bit confused. It will be a great help for me if you look into my code and clarify. Thanks a lot in advance. ########## spring.xml ########### <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!-- XID factory --> <bean id="xidFactory" class="org.apache.geronimo.transaction.manager.XidFactoryImpl" /> <!-- Transaction log --> <bean id="transactionLog" class="org.jencks.factory.HowlLogFactoryBean"> <property name="logFileDir" value="./log/txlog"/> <property name="xidFactory" ref="xidFactory"/> </bean> <!-- #### Transaction Manager #### --> <bean id="transactionContextManager" class="org.jencks.factory.TransactionContextManagerFactoryBean" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default"> <property name="transactionLog" ref="transactionLog"/> </bean> <bean id="userTransaction" class="org.jencks.factory.GeronimoTransactionManagerFactoryBean" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default" /> <bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default"> <property name="userTransaction" ref="userTransaction" /> </bean> <!-- #### Connection Manager #### --> <bean id="connectionTracker" class="org.apache.geronimo.connector.outbound.connectiontracking.ConnectionTrackingCoordinator"/> <bean id="connectionManager" class="org.jencks.factory.ConnectionManagerFactoryBean"> <property name="transactionSupport"> <bean class="org.jencks.factory.XATransactionFactoryBean"> <property name="useTransactionCaching" value="true" /> <property name="useThreadCaching" value="true" /> </bean> </property> <property name="poolingSupport"> <bean class="org.jencks.factory.SinglePoolFactoryBean"> <property name="maxSize" value="2" /> <property name="minSize" value="1" /> <property name="blockingTimeoutMilliseconds" value="60" /> <property name="idleTimeoutMinutes" value="60" /> <property name="matchOne" value="true" /> <property name="matchAll" value="true" /> <property name="selectOneAssumeMatch" value="true" /> </bean> </property> <property name="connectionTracker" ref="connectionTracker"/> </bean> <!-- Datasource and Hibernate setup: --> <bean id="ta20dbMCF" class="org.jencks.tranql.XAPoolDataSourceMCF" lazy-init="true"> <property name="driverName" value="com.mysql.jdbc.Driver" /> <property name="user" value="root" /> <property name="password" value="" /> <property name="url" value="jdbc:mysql://localhost/test" /> </bean> <bean id="ta20dbDataSource" lazy-init="true" class="org.springframework.jca.support.LocalConnectionFactoryBean"> <property name="managedConnectionFactory"> <ref local="ta20dbMCF"/> </property> <property name="connectionManager"> <ref bean="connectionManager"/> </property> </bean> <bean id="ta20dbHibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="properties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop> </props> </property> </bean> <bean id="ta20dbMappingResources" class="java.util.Vector"> <constructor-arg> <list> <value>com/epe/Honey.hbm.xml</value> <value>com/epe/HoneyExtraInfo.hbm.xml</value> </list> </constructor-arg> </bean> <bean id="ta20dbSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource"> <ref local="ta20dbDataSource"/> </property> <property name="hibernateProperties"> <ref bean="ta20dbHibernateProperties" /> </property> <!-- OR mapping files. --> <property name="mappingResources" ref="ta20dbMappingResources"/> <property name="jtaTransactionManager"> <ref bean="userTransaction"/> </property> </bean> <bean id="myEpe" class="com.epe.MyEPE"> <property name="sessionFactory" ref="ta20dbSessionFactory"/> <property name="transactionManager" ref="txManager"/> </bean> </beans> ######## MyEPE.java ######### package com.epe; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.DefaultTransactionDefinition; public class MyEPE{ private SessionFactory sessionFactory; private PlatformTransactionManager transactionManager; public void setSessionFactory(SessionFactory sessionFactory) { this.sessionFactory=sessionFactory; } public void execute(){ Honey forestHoney = new Honey(); forestHoney.setName("forest honey"); forestHoney.setTaste("very sweet"); Honey countryHoney = new Honey(); countryHoney.setName("countryi honey"); countryHoney.setTaste("tasty"); DefaultTransactionDefinition definition=new DefaultTransactionDefinition(); definition.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status=transactionManager.getTransaction(definition); try{ Thread arr[]=new Thread[100]; for(int i=0;i<100;i++){ Honey obj = new Honey(); obj.setName("Honey"+i); arr[i]= new AddRule(sessionFactory,obj); } for(int i=0;i<100;i++) arr[i].start(); for(int i=0;i<100;i++) arr[i].join(); Session tmp=((AddRule)arr[0]).getSession(); System.out.println("Conn Status before commit/rollback:"+tmp.isOpen()); transactionManager.commit(status); System.out.println("Conn Status after commit/rollback:"+tmp.isOpen()); }catch(Exception e){ e.printStackTrace(); } } public PlatformTransactionManager getTransactionManager() { return transactionManager; } public void setTransactionManager(PlatformTransactionManager transactionManager) { this.transactionManager = transactionManager; } } ########## BaseRule.java ######### package com.epe; import org.hibernate.Session; public abstract class BaseRule extends Thread { Session session; BaseRule(Session session){ this.session=session; } public Session getSession() { return session; } public void setSession(Session session) { this.session = session; } } ######### AddRule.java ###### package com.epe; import org.hibernate.SessionFactory; public class AddRule extends BaseRule { Honey honey; AddRule(SessionFactory sessionFactory,Honey data){ super(sessionFactory.getCurrentSession()); this.honey=data; } public void run(){ try { session.persist(honey); Thread.sleep(500); } catch (Exception e) { e.printStackTrace(); } } }
|
|
|
Re: Does jencks canbe integrated with hybernate?As I already said, distributed transactions are transactions involving
several resources that may be remote (a database, jms broker, etc...). But such transactions must be used within a single thread. So what you are trying to do is certainly not permitted by both jta and spring. If you need the whole process to be transacted, the only choice is to have everything running sequentially. And the opposite: if you want to work to be splitted across several threads (or even computers), you can not use a single transaction. If the processing time (apart from accessing the database) is length, you could use several threads for it, but all database access must be done from a single thread. On 9/25/07, Arif Mohd <arif.mohammed1@...> wrote: > > Hi, > > Iam new to this jencks and even to hybernate. Just i want to know can i > integrate jencks with hybernate. My requirement is there are 3 threads, 2 of > them are hybernate session threads doing some DB operation and one more > thread is using ActiveMQ. I want to make use of jenks for maintaing > distributed transactions over these threads > -- > View this message in context: http://www.nabble.com/Does-jencks-canbe-integrated-with-hybernate--tf4514305.html#a12875825 > Sent from the jencks - user mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > -- Cheers, Guillaume Nodet ------------------------ Blog: http://gnodet.blogspot.com/ --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Does jencks canbe integrated with hybernate?But my business logic is all these processing logic(threads) are independent, so i want to execute them parallely but if one business operation fails none of them should succeed.
so as you can see in the code iam just calling session.persist() method and not commiting to DB, once all the threads have completed their work iam calling commit on transaction manager(here i want to make use of transaction manager) also all the DB operations are done in one thread. Does it make sence? or if you have any better idea of doing these(running parallely but atlast should be committed at one point) please let me know.
|
|
|
Re: Does jencks canbe integrated with hybernate?Hi gnodet,
Could you please answer my question as explained above.Ofcourse i also attached activemq with the transaction manager and rolling back,commiting of transactions are happening perfectly. The flow is very simple once the message is posted in activemq these threads starts executing parallely if any one of thread fails all the processing of threads will be rolled back and even the message in activemq is rolled back.
|
|
|
Re: Does jencks canbe integrated with hybernate?There is no way to do what you want afaik
You need to either: * use a single transaction from a single thread * use multiple threads and do manual compensation (which is manual rollback) You can also use multiple threads and multiple transactions, but a transaction rollback wil only rollback the transaction for its own thread. On 10/4/07, Arif Mohd <arif.mohammed1@...> wrote: > > Hi gnodet, > > Could you please answer my question as explained above.Ofcourse i > also attached activemq with the transaction manager and rolling > back,commiting of transactions are happening perfectly. > > The flow is very simple once the message is posted in activemq these > threads starts executing parallely if any one of thread fails all the > processing of threads will be rolled back and even the message in activemq > is rolled back. > > > Arif Mohd wrote: > > > > But my business logic is all these processing logic(threads) are > > independent, so i want to execute them parallely but if one business > > operation fails none of them should succeed. > > > > so as you can see in the code iam just calling session.persist() > > method and not commiting to DB, once all the threads have completed their > > work iam calling commit on transaction manager(here i want to make use of > > transaction manager) also all the DB operations are done in one thread. > > > > Does it make sence? or if you have any better idea of doing > > these(running parallely but atlast should be committed at one point) > > please let me know. > > > > > > gnodet wrote: > >> > >> As I already said, distributed transactions are transactions involving > >> several resources that may be remote (a database, jms broker, etc...). > >> But such transactions must be used within a single thread. > >> So what you are trying to do is certainly not permitted by both jta and > >> spring. > >> > >> If you need the whole process to be transacted, the only choice is to > >> have everything running sequentially. And the opposite: if you want > >> to work to be splitted across several threads (or even computers), you > >> can not use a single transaction. > >> > >> If the processing time (apart from accessing the database) is length, > >> you could use several threads for it, but all database access must be > >> done from a single thread. > >> > >> On 9/25/07, Arif Mohd <arif.mohammed1@...> wrote: > >>> > >>> Hi, > >>> > >>> Iam new to this jencks and even to hybernate. Just i want to know can > >>> i > >>> integrate jencks with hybernate. My requirement is there are 3 threads, > >>> 2 of > >>> them are hybernate session threads doing some DB operation and one more > >>> thread is using ActiveMQ. I want to make use of jenks for maintaing > >>> distributed transactions over these threads > >>> -- > >>> View this message in context: > >>> http://www.nabble.com/Does-jencks-canbe-integrated-with-hybernate--tf4514305.html#a12875825 > >>> Sent from the jencks - user mailing list archive at Nabble.com. > >>> > >>> > >>> --------------------------------------------------------------------- > >>> To unsubscribe from this list please visit: > >>> > >>> http://xircles.codehaus.org/manage_email > >>> > >>> > >> > >> > >> -- > >> Cheers, > >> Guillaume Nodet > >> ------------------------ > >> Blog: http://gnodet.blogspot.com/ > >> > >> --------------------------------------------------------------------- > >> To unsubscribe from this list please visit: > >> > >> http://xircles.codehaus.org/manage_email > >> > >> > >> > > > > > > -- > View this message in context: http://www.nabble.com/Does-jencks-canbe-integrated-with-hybernate--tf4514305.html#a13032903 > Sent from the jencks - user mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe from this list please visit: > > http://xircles.codehaus.org/manage_email > > -- Cheers, Guillaume Nodet ------------------------ Blog: http://gnodet.blogspot.com/ --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Does jencks canbe integrated with hybernate?Arif Mohd wrote:
> Hi gnodet, > > Could you please answer my question as explained above.Ofcourse i > also attached activemq with the transaction manager and rolling > back,commiting of transactions are happening perfectly. > > The flow is very simple once the message is posted in activemq these > threads starts executing parallely if any one of thread fails all the > processing of threads will be rolled back and even the message in activemq > is rolled back. > Do you want distributed transactions with 2PC or to share a single Hibernate session across threads? -- Christopher G. Stach II --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Does jencks canbe integrated with hybernate?Hi Christopher,
I need distributed trasactions with 2pc(this is achieved with jencks, i combined MySQL DB access and ActiveMQ transaction with this) also i need to share the hibernate session across multiple threads.Why i need to share the session across multiple threads is, these threads are independent so i can save time executing them parallely instead of doing sequentially. Ofcourse the main thread which created child threads will wait till the childs has processed then it will commit/rollback on transaction manager(which also commits/rollback the activeMQ transaction). You can see the code i have attached in this thread.Generally handling this kind of problem should be possible but iam running out of ideas.
|
|
|
Re: Does jencks canbe integrated with hybernate?Arif Mohd wrote:
> Hi Christopher, > > I need distributed trasactions with 2pc(this is achieved with jencks, i > combined MySQL DB access and ActiveMQ transaction with this) also i need to > share the hibernate session across multiple threads.Why i need to share the > session across multiple threads is, these threads are independent so i can > save time executing them parallely instead of doing sequentially. Ofcourse > the main thread which created child threads will wait till the childs has > processed then it will commit/rollback on transaction manager(which also > commits/rollback the activeMQ transaction). > > You can see the code i have attached in this thread.Generally > handling this kind of problem should be possible but iam running out of > ideas. As Guillaume said, you can't do that. You can have multiple distributed Hibernate sessions participating in the same transaction if you write some kind of ResourceAdapter(s) for the TM to use, or use something like WS-Transaction or Jini. -- Christopher G. Stach II --------------------------------------------------------------------- To unsubscribe from this list please visit: http://xircles.codehaus.org/manage_email |
|
|
Re: Does jencks canbe integrated with hybernate?Hi Christopher,
Could you please provide me some pointer or examples to acheive this.
|
| Free embeddable forum powered by Nabble | Forum Help |