Re: [Resin-interest] specify data source for ejb manager

2014-01-10 Thread Riccardo Cohen
Thanks Scott.

I managed to retreive information from 2 db with EntityManagerFactory 
associated correctly with the good database, thanks to jta-data-source 
parameter in persistence.xml.

But for updating the database the factory is useless and I need to use a 
global injected EntityManager with a global injected UserTransaction 
(with the factory the database is not updated)

   @Inject @Named(adlresintestunit1) EntityManager m_ejb1;
   @Inject @Named(adlresintestunit2) EntityManager m_ejb2;
   @Inject UserTransaction m_ut;

The data is correctly inserted in the good database, but despite the 
m_ut.commit(), there is an exception at the end of the http request 
handling :

[2014-01-10 08:39:38.227] {resin-port-8000-69} 
java.lang.IllegalStateException: Resource 
UserConnection[ManagedConnectionImpl[jdbc/adlresintest1.d0.0]] was not 
closed. Applications must close all resources in a finally block.
at 
com.caucho.transaction.UserTransactionImpl.clearDanglingResources(UserTransactionImpl.java:470)
at 
com.caucho.transaction.UserTransactionImpl.abortTransaction(UserTransactionImpl.java:423)
at 
com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:175)
at 
com.caucho.server.webapp.AccessLogFilterChain.doFilter(AccessLogFilterChain.java:95)
at 
com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:289)
at 
com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:838)
at 
com.caucho.network.listen.TcpSocketLink.dispatchRequest(TcpSocketLink.java:1346)
at 
com.caucho.network.listen.TcpSocketLink.handleRequest(TcpSocketLink.java:1302)
at 
com.caucho.network.listen.TcpSocketLink.handleRequestsImpl(TcpSocketLink.java:1286)
at 
com.caucho.network.listen.TcpSocketLink.handleRequests(TcpSocketLink.java:1194)
at 
com.caucho.network.listen.TcpSocketLink.handleAcceptTaskImpl(TcpSocketLink.java:993)
at 
com.caucho.network.listen.ConnectionTask.runThread(ConnectionTask.java:117)
at 
com.caucho.network.listen.ConnectionTask.run(ConnectionTask.java:93)
at 
com.caucho.network.listen.SocketLinkThreadLauncher.handleTasks(SocketLinkThreadLauncher.java:169)
at 
com.caucho.network.listen.TcpSocketAcceptThread.run(TcpSocketAcceptThread.java:61)
at 
com.caucho.env.thread2.ResinThread2.runTasks(ResinThread2.java:173)
at 
com.caucho.env.thread2.ResinThread2.run(ResinThread2.java:118)



I put my full small sample here :

http://www.realty-property.com/zdev/31-testmultidb.zip

Thanks for any help.


On 09/01/2014 18:59, Scott Ferguson wrote:
 On 1/3/14, 5:15 AM, Riccardo Cohen wrote:
 Hello
 I will soon have more than one mysql server. I want to use one server
 for read requests of static data, the other for read/write requests of
 dynamic data. It works for sql requests through datasource, but I cannot
 find how to do it with ejb manager.

 In my resin.xml I have this :

database jndi-name=jdbc/adlresintest
  ...
/database
ejb-server data-source=jdbc/adlresintest
 create-database-schema=false
  jndi-name=ejb/
database jndi-name=jdbc/adlresintest2
  ...
/database
ejb-server data-source=jdbc/adlresintest2
 create-database-schema=false
  jndi-name=ejb2/

 In persistence.xml  :

 persistence xmlns=http://java.sun.com/xml/ns/persistence; version=1.0
  persistence-unit name=adlresintestunit
providerorg.eclipse.persistence.jpa.PersistenceProvider/provider
classadlresintest.Adluser/class
exclude-unlisted-classes /
properties
  property name=eclipselink.ddl-generation.output-mode
 value=database /
  property name=eclipselink.weaving.fetchgroups value=false/
/properties
  /persistence-unit
 /persistence

 In my java code I have this :

  @Inject @Named(jdbc/adlresintest) public DataSource
 m_datasource1;// public site
  @Inject @Named(jdbc/adlresintest2) public DataSource
 m_datasource2;// not used for the moment
  @PersistenceUnit(name=adlresintestunit) @Named(ejb)
 EntityManagerFactory ejbfactory1;
  @PersistenceUnit(name=adlresintestunit) @Named(ejb2)
 EntityManagerFactory ejbfactory2;


 When using datasource1 or 2 I access the correct database. But when
 using ejbfactory1 or 2, only the second database is accessed. The
 association created with jndi-name and @Named() works for
 DataSource/database but not for EntityManagerFactory/ejb-server.

 I also tried 

Re: [Resin-interest] specify data source for ejb manager

2014-01-09 Thread Scott Ferguson
On 1/3/14, 5:15 AM, Riccardo Cohen wrote:
 Hello
 I will soon have more than one mysql server. I want to use one server
 for read requests of static data, the other for read/write requests of
 dynamic data. It works for sql requests through datasource, but I cannot
 find how to do it with ejb manager.

 In my resin.xml I have this :

   database jndi-name=jdbc/adlresintest
 ...
   /database
   ejb-server data-source=jdbc/adlresintest
 create-database-schema=false
 jndi-name=ejb/
   database jndi-name=jdbc/adlresintest2
 ...
   /database
   ejb-server data-source=jdbc/adlresintest2
 create-database-schema=false
 jndi-name=ejb2/

 In persistence.xml  :

 persistence xmlns=http://java.sun.com/xml/ns/persistence; version=1.0
 persistence-unit name=adlresintestunit
   providerorg.eclipse.persistence.jpa.PersistenceProvider/provider
   classadlresintest.Adluser/class
   exclude-unlisted-classes /
   properties
 property name=eclipselink.ddl-generation.output-mode
 value=database /
 property name=eclipselink.weaving.fetchgroups value=false/
   /properties
 /persistence-unit
 /persistence

 In my java code I have this :

 @Inject @Named(jdbc/adlresintest) public DataSource
 m_datasource1;// public site
 @Inject @Named(jdbc/adlresintest2) public DataSource
 m_datasource2;// not used for the moment
 @PersistenceUnit(name=adlresintestunit) @Named(ejb)
 EntityManagerFactory ejbfactory1;
 @PersistenceUnit(name=adlresintestunit) @Named(ejb2)
 EntityManagerFactory ejbfactory2;


 When using datasource1 or 2 I access the correct database. But when
 using ejbfactory1 or 2, only the second database is accessed. The
 association created with jndi-name and @Named() works for
 DataSource/database but not for EntityManagerFactory/ejb-server.

 I also tried to use composite persistence unit as written here :
 http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Composite_Persistence_Units
 but I could not find the good configuration to do it, the tag
 jta-data-source was not accepted. I could not find in
 http://eclipse.org/eclipselink/documentation/2.4/jpa/extensions/persistenceproperties_ref.htm
 which property to set for the datasource.

The configuration should be jta-data-source and non-jta-data-source 
in the persistence-unit:

persistence ...
   persistence-unit name=test ...
 jta-data-sourcejdbc/adlresintest/jta-data-source
 ...
   /persistence-unit
   persistence-unit name=test2 ...
jta-data-sourcejdbc/adlresintest2/jta-data-source
   ...

Since the jta-data-source tag is part of the JPA spec, it should be 
recognized by eclipse-link.

-- Scott


 Thanks a lot.



___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest