-
1. Re: VERY simple multiple datasources
scatudal Jul 13, 2009 8:41 PM (in response to hardaur)Hi Gerald,
I did something similar for a project I'm working on. I added ano-tx-datasource
in 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.
Sylvain
-
2. Re: VERY simple multiple datasources
hardaur Jul 13, 2009 8:51 PM (in response to hardaur)Sylvain,
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.
Gerald
-
3. Re: VERY simple multiple datasources
scatudal Jul 13, 2009 9:09 PM (in response to hardaur)I don't have time to test it, but here is what I would try:
Add a
no-tx-datasource
datasource 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! ;)
Sylvain
-
4. Re: VERY simple multiple datasources
hardaur Jul 14, 2009 1:46 PM (in response to hardaur)With some minor tweaking due to my specific configuration, that was it ; )
Thanks!
Gerald
-
5. Re: VERY simple multiple datasources
asookazian Jul 14, 2009 4:00 PM (in response to hardaur)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?
-
6. Re: VERY simple multiple datasources
scatudal Jul 14, 2009 5:18 PM (in response to hardaur)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
Sylvain
-
7. Re: VERY simple multiple datasources
jeanluc Jul 14, 2009 5:33 PM (in response to hardaur)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).