-
1. Re: Share seam jar files across applications
binnyg Jan 28, 2009 6:47 PM (in response to binnyg)So, I created a separate java project and packaging it as a jar file. Seems to be working fine but I want to understand it little better. I let seam handle my transactions.
This project has
a component.xml
I just have two entries in it.<persistence:managed-persistence-context name="rolesEntityManager" auto-create="true" entity-manager-factory="#{rolesEntityManagerFactory}"/> <persistence:entity-manager-factory name="rolesEntityManagerFactory" persistence-unit-name="roles"/>
I have a datasource file
<datasources> <local-tx-datasource> <jndi-name>rolesDS</jndi-name> <connection-url>jdbc:mysql://localhost:3306/roles?jdbcCompliantTruncation=false</connection-url> <driver-class>com.mysql.jdbc.Driver</driver-class> <user-name>user</user-name> <password>password</password> </local-tx-datasource> </datasources>
I included this jar file in a webproject. When I invoke methods from this project, I started getting all sorts of transaction errors like cannot enlist in the current transaction. After fiddling around with the team we ended up with a working solution. Which is is to remove datasource file and created a roles-service.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE server> <server> <mbean code="com.mchange.v2.c3p0.mbean.C3P0PooledDataSource" name="jboss:service=rolesDataSource"> <attribute name="JndiName">java:rolesDS</attribute> <attribute name="DriverClass">org.gjt.mm.mysql.Driver</attribute> <attribute name="JdbcUrl">jdbc:mysql://localhost:3306/roles</attribute> <attribute name="User">user</attribute> <attribute name="Password">password</attribute> <attribute name="AcquireIncrement">3</attribute> <attribute name="IdleConnectionTestPeriod">1800</attribute> <attribute name="InitialPoolSize">3</attribute> <attribute name="MaxIdleTime">0</attribute> <attribute name="MaxPoolSize">50</attribute> <attribute name="MinPoolSize">10</attribute> <attribute name="PreferredTestQuery">SELECT 1</attribute> <depends>jboss:service=Naming</depends> </mbean> </server>
We have a theory that
local-tx-datasource
in datasource file is causing this issue. Since JBoss is managing transaction manager we get these errors. If you look at roles-service.xml it is a C3P0Datasource. We do not see these transaction errors any more.So here is my question.
1. When you have two persistence managers defined in component.xml how are transactions handled? I understand seam starts a transaction before RESTOREVIEW if it is JTA and before APPLY-REQUEST phase if it is RESOURCELOCAL and the whole nine yard. But I am having trouble understanding how transactions work when I have two different databases and how are they tied to JDBC transactions.
2. How did the above approach solve my problem?Would appreciate any links to the documentation referring this scenario.