You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.
| Online: | 10 Members of 9199 |
| Forum: Seam Users |
23. Jul 2008, 19:30 America/New_York | Link |
Hello,
I have read a couple of posts about people using multiple datasources within their seam app without using xa-datasource. How is this possible? I would love to stop using xa datasources, but I don't see how.
For instance: link
the post was never resolved, but no-one suggested that the approach is simply not possible.. Whenever I try to configure this way, I get:
Could not enlist in transaction on entering meta-aware object
see: link
any help?
-Dustin
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
in your jbossjta-properties.xml file.Read further info about this here.
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
Obviously I can't use the transaction from Transaction.instance(), so how can I create a new useable transaction?
any more help?
-Dustin
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>
`
Thx for this hint!
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
But I still get
Any other hints? What else am I missing?
I think thats a different problem. Please post a detailed usecase in a new post.
Is it still true if one of the datasources is read-only?
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;