Thanks Romain. 

Ignite is using static variables internally to track it's cache instances, so 
EntityManagerFactory and Ignite must be initiated by the same classloader, not 
sure if it will create problem with custom resource for Ignite, I will try to 
play with it and lazy persistence unit later.
 
For now I would like to figure out how to instantiate the DataSource properly 
using class-name/factory-name approach (I'm going to need this for another use 
case as well).

I can see the 
https://github.com/apache/tomee/blob/master/container/openejb-core/src/test/java/org/apache/openejb/config/typed/util/ServerContextTest.java
 is using DataSourceBuilder and ServerContext to create the DataSource 
resource. Is there anything like that can be used from my custom factory method?

Cheers,
Dmitry

-----Original Message-----
From: Romain Manni-Bucau [mailto:[email protected]] 
Sent: Thursday, September 27, 2018 12:28 PM
To: [email protected]
Subject: Re: Apache Ignite initialization before EntityManagerFactory

This works, you can also create an ignite resource just to create ignite 
instance.

That said, did you try to make your persistence unit lazy? Can make it working 
and let you start ignite from your app.

Le jeu. 27 sept. 2018 21:01, Shultz, Dmitry <[email protected]> a écrit 
:

> Figured out some way to make sure Ignite is initialized before 
> EntityManagerFactory, not sure if it's the right way though. Please 
> let me know if I'm doing something conceptually wrong here.
>
> I'm trying to use the  class-name and factory-name (as described here:
> http://tomee.apache.org/application-resources.html) to make sure the 
> DataSource is initialized after Ignite.start() is called. The sequence 
> problem seems to be resolved, but I'm not sure how to properly 
> manually instantiate the JTA managed datasource.
>
> Here is my resources.xml:
>
> <resources>
>
>     <Resource id="myDS" type="javax.sql.DataSource"
> class-name="com.bla.bla.DataSourceFactory" factory-name="create">
>         JdbcDriver   = org.postgresql.Driver
>         JdbcUrl      = jdbc:postgresql://localhost:5432/mydb
>         UserName     = user
>         Password     = test
>         maxActive = 10
>         maxIdle = 10
>         TestOnBorrow = true
>         TestWhileIdle = true
>         TestOnReturn = true
>         ValidationQuery = SELECT 1
>         JtaManaged=true
>     </Resource>
> </resources>
>
>
> Here is my factory method (ofcom.bla.bla.DataSourceFactory):
>
> public Object create() {
>
>         initIgnite();
>
>         BasicManagedDataSource resource = new 
> BasicManagedDataSource("myDB");
>         resource.setJdbcDriver("org.postgresql.Driver");
>         resource.setJdbcUrl("jdbc:postgresql://localhost:5432/mydb");
>         resource.setUserName("user");
>         resource.setPassword("test");
>         resource.setTestOnBorrow(true);
>         resource.setTestWhileIdle(true);
>         resource.setTestOnReturn(true);
>         resource.setValidationQuery("SELECT 1");
>
>         return resource;
>     }
>
> BasicManagedDataSource doesn't have the setJtaManaged(), so it's 
> probably not a good choice... Also, and I'm seeing this in the log:
>
> 27-Sep-2018 18:26:50.516 WARNING [http-nio-8080-exec-4] 
> org.apache.openejb.assembler.classic.Assembler.unusedProperty unused 
> property 'JdbcDriver' for resource 'my-app/myDS'
> 27-Sep-2018 18:26:50.516 WARNING [http-nio-8080-exec-4] 
> org.apache.openejb.assembler.classic.Assembler.unusedProperty unused 
> property 'JdbcUrl' for resource 'my-app / myDS '
> 27-Sep-2018 18:26:50.516 WARNING [http-nio-8080-exec-4] 
> org.apache.openejb.assembler.classic.Assembler.unusedProperty unused 
> property 'UserName' for resource 'my-app / myDS '
> 27-Sep-2018 18:26:50.516 WARNING [http-nio-8080-exec-4] 
> org.apache.openejb.assembler.classic.Assembler.unusedProperty unused 
> property 'Password' for resource 'my-app / myDS '
> ...
>
>
> From: Shultz, Dmitry
> Sent: Thursday, September 27, 2018 10:03 AM
> To: [email protected]
> Subject: Apache Ignite initialization before EntityManagerFactory
>
> Hi All,
>
> I'm trying to use Apache Ignite as a L2 cache in my app.
>
> Both JPA/Hibernate and Ignite are configured to work together, but I'm 
> not sure how to make the Ignite to started before JPA/Hibernate is 
> initialized.
> Right now the war deployment fails when deployer is trying to create 
> EntityManagerFactory and can't find the specified (in persistence.xml) 
> Ignite instance. Do I have to deploy another app (with Ignite.start() 
> in
> it) before the 'main' app or there is some other way to do it?
>
> Cheers,
> Dmitry
>
>

Reply via email to