-
1. Re: Multiple (non-xa)datasources?
gjeudy Jul 23, 2008 8:05 PM (in response to dustismo)I would recommend using XA datasources if you plan to have multiple datasources participating in the same transaction.
If you absolutely need to keep local datasources then you need to access each one from a separate transaction.
If you can't do this then you can enable multiple local datasources in the same JBossTS transaction, even though this is not recommended (don't be fooled you have no atomicity guarantees with this approach).
You would have to enable
<property name="com.arjuna.ats.jta.allowMultipleLastResources" value="true"/>
in your jbossjta-properties.xml file.Read further info about this here.
-
2. Re: Multiple (non-xa)datasources?
dustismo Jul 23, 2008 11:27 PM (in response to dustismo)Excellent, thanks for the response.
I have a secondary datasource that is used very rarely, so I don't mind handling the transactions for it by hand. I have no idea how to do that though. the following does not work:
EntityManager em = (EntityManager)Component.getInstance("secondEntityManager",true); em.getTransaction().begin(); Object result = em.createNativeQuery( "SELECT blah blah").getSingleResult(); em.getTransaction().commit();
I get
java.lang.IllegalStateException: JTA EntityManager cannot access a transactions at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:316) at org.jboss.seam.persistence.EntityManagerProxy.getTransaction(EntityManagerProxy.java:110) at com.trendrr.servlet.api.admin.TorrentSearchStats.process(TorrentSearchStats.java:25) ...
Obviously I can't use the transaction from Transaction.instance(), so how can I create a new useable transaction?
any more help?
-Dustin
-
3. Re: Multiple (non-xa)datasources?
dustismo Jul 24, 2008 12:07 AM (in response to dustismo)I got it too work..
To answer my own question:
add transaction-type equal to RESOURCE_LOCAL and change to non-jta-data-source in persistence.xml
`
<persistence-unit name="second-unit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<non-jta-data-source>java:/secondDatasource</non-jta-data-source>
</persistence-unit>
` -
4. Re: Multiple (non-xa)datasources?
accless Aug 15, 2008 10:31 AM (in response to dustismo)Thx for this hint!
-
5. Re: Multiple (non-xa)datasources?
squirrel Sep 8, 2008 8:42 PM (in response to dustismo)Well I must still be missing something. I've tried this and other techniques, but it still seems to try to bind all the entities to every datasource. The entities are all annotated with
@PersistenceContext(unitName="MainDatasource")
But I still get
[ServiceController] Problem starting service persistence.units:ear=myproject-ear.ear,unitName=OtherDatasource javax.persistence.PersistenceException: org.hibernate.HibernateException: Missing table: MainDatasourceTable
Any other hints? What else am I missing?
-
6. Re: Multiple (non-xa)datasources?
gjeudy Sep 8, 2008 10:07 PM (in response to dustismo)I think thats a different problem. Please post a detailed usecase in a new post.
-
7. Re: Multiple (non-xa)datasources?
vanyatka Jan 28, 2009 10:22 PM (in response to dustismo)
I would recommend using XA datasources if you plan to have multiple datasources participating in the same transaction.Is it still true if one of the datasources is read-only?
If you absolutely need to keep local datasources then you need to access each one from a separate transaction.Correct me if I'm wrong, but you cannot suspend or create a new transaction if you're using Seam POJOs:
/** * Transaction propagation strategies for Seam JavaBean * components. Note that unlike EJB3 components, there * are no strategies for suspending transactions. * * @author Gavin King * */ public enum TransactionPropagationType { REQUIRED, MANDATORY, SUPPORTS, NEVER;