Help

Controls

PermLinkWikiLink

Built with Seam

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.

Forum: Seam Users Forum ListTopic List
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

7 Replies:
23. Jul 2008, 20:05 America/New_York | Link

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.

Rating:  * * * *
23. Jul 2008, 23:27 America/New_York | Link

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

24. Jul 2008, 00:07 America/New_York | Link
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>
`
15. Aug 2008, 10:31 America/New_York | Link

Thx for this hint!

08. Sep 2008, 20:42 America/New_York | Link

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?

08. Sep 2008, 22:07 America/New_York | Link

I think thats a different problem. Please post a detailed usecase in a new post.

28. Jan 2009, 22:22 America/New_York | Link
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;