I did something similar for a project I'm working on. I added a
no-tx-datasourcein my datasource file and than added another persistence unit in my persistence.xml file. This new persistence unit is not managed by seam because I don't need it to be. I think it's the same for you. Then you just need to have you persistence context injected by the container like this :
@PersistenceContext( unitName = "whateverYouNameIt" ) EntityManager whateverYouNameIt;
Note that for the container to inject the persistence context, the class must be an EJB.
Hope this helps.
Thanks very much for your response! Unfortunately the Seam app is a mature WAR app, not EJB. Anyway to do something similar in that situation? It seems you are right on the money as to what I'm after though.
I don't have time to test it, but here is what I would try:
no-tx-datasourcedatasource in whatever-ds.xml :
<no-tx-datasource> <jndi-name>fooDatasource</jndi-name> <connection-url>...</connection-url> <driver-class>...</driver-class> <user-name>...</user-name> <password>...</password> </no-tx-datasource>
Add a persistence unit in persistence.xml :
<persistence-unit name="foo"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>java:/fooDatasource</jta-data-source> <properties> <property name="hibernate.dialect" value="..."/> <property name="hibernate.show_sql" value="false"/> <property name="hibernate.format_sql" value="false"/> <property name="jboss.entity.manager.factory.jndi.name" value="java:/fooEntityManagerFactory"/> </properties> </persistence-unit>
And finally add a new managed persistence context in component.xml :
<persistence:managed-persistence-context name="fooEntityManager" auto-create="true" persistence-unit-jndi-name="java:/fooEntityManagerFactory" />
You should now be able to have seam inject an EntityManager with this :
@In EntityManager fooEntityManager;
Hoping I'm not misleading you! ;)
With some minor tweaking due to my specific configuration, that was it ; )
What are the differences between using <local-tx-datasource> vs. <no-tx-datasource> in foo-ds.xml?
Does this cause JPA not to use the cache, for example? Or is it a performance optimization in the case of using JDBC/sprocs?
local-tx-datasource is Transactional while no-tx-datasource is not transactional.
If you need to have both connection transactional, you'll need to read a bit because I haven't done that yet.
Here is a link where you can get more info : Configuring JDBC DataSources
You need to select the datasource according to the nature of the data source. That is, select <no-tx-datasource> if the data source is not transactional (such as an LDAP source or something using file system operations, for instance).