Hi Mike,

If you could explain a bit on our goals that would helpful. From the description it sounds like you're testing all possible ways to persist data. If I understand correctly, you have this setup:

(A) 1. An EntityManagerFactory created by you outside the container -- this EMF and any EntityManagers are not container aware, will not use the container db pool, and will not participate in container created transactions. The EntityTransaction API must be used to start/ stop transactions. Data will not be guaranteed to flush outside of an EntityTransaction.

(B) 2-4. An EntityManager is injected/looked up in your Stateless bean -- not an EntityManagerFactory (correct me if I'm wrong). This EntityManager is pointing to the same database, but will be using the container's connection pool and a container controlled datasource. The EntityManager will participate in JTA transactions. No details were given as to who or how the Stateless bean is invoked, so I assume there is no transaction in progress. In that case the container will begin and commit a new transaction around each call to the Stateless bean. Under the covers a new EntityManager instance will be created at the beginning of each transaction and flushed at the end of each transaction.

(C) 5. The same Stateless bean also has a reference to an EJB 2.x Container-Managed Persistence EntityBean. Is that right? How is this 2.x CMP EntityBean configured?

6. When you say "the result list", which persistence approach are you using to read the data; A, B or C?

Just as a general note, the three persistence approaches (A, B, and C) will have zero awareness of each other and will not see the data of the other till the "cache" they hold is flushed to the database. This will be around transactional boundaries by default. If any of them are used in the same transaction, you will have consistency and integrity issues if they attempt to operate on the same data. The same thing can happen if data is passed between them at any time which can result in dirty reads.

If you have some insight on your goals and design constraints, that would be very helpful.

Look forward to your info, hope we can point you in the right direction.

-David


On Aug 18, 2009, at 9:40 AM, mikeho wrote:




Hi,

Essentially what I am trying to is:
1) create a EntityManagerFactory outside of the container and use its em
to persist some fixtures.
        
        final Properties p = new Properties();
p.put("javax.persistence.jdbc.driver", "org.hsqldb.jdbcDriver");
       p.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:hsqldb");
       p.put("eclipselink.target-database",
"org.eclipse.persistence.platform.database.HSQLPlatform");
       p.put("javax.persistence.jdbc.user", "sa");
       p.put("javax.persistence.jdbc.password", "");
       p.put("eclipselink.ddl-generation", "drop-and-create-tables");
       p.put("eclipselink.ddl-generation.output-mode", "database");
        emf = Persistence.createEntityManagerFactory(
                   this.persistenceUnitName, p);

 2) I then create the InitialContext using the properties below:

        final Properties p = new Properties();
       p.put(Context.INITIAL_CONTEXT_FACTORY,

       p.put("jdbc/BrandGroupXADS", "new://Resource?type=DataSource");
p.put("jdbc/BrandGroupXADS.JdbcDriver", "org.hsqldb.jdbcDriver");
       p.put("jdbc/BrandGroupXADS.JdbcUrl", "jdbc:hsqldb:mem:hsqldb");
       p.put("jdbc/BrandGroupXADS.eclipselink.jdbc.user", "sa");
       p.put("jdbc/BrandGroupXADS.eclipselink.jdbc.password", "");
       p.put("jdbc/BrandGroupXADS.eclipselink.target-database",
"org.eclipse.persistence.platform.database.HSQLPlatform");

 3) The persistence.xml looks like this (note no properties just the
classes):

        <persistence-unit name="brandgroupPU" >
                
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
                <jta-data-source>jdbc/BrandGroupXADS</jta-data-source>

                classes...

             </persistence-unit>
        </persistence>
        
  4) I now do a jndi lookup for a staleless session bean and invoke a
method to return the entity(s) persisted in step 1).
     It does this happily.

5) I then invove a method on the same SSB to insert another entity. CMP
is used.

6) I repeat step 4) and the entity applied in step 5) does not appear in
the result list.

  7) I do have the following arg on my cammand
line:-javaagent:{path}/openejb-javaagent-3.0.jar


I've looked on the forum and tried various things. I'm beginning to think
that I am overlooking something simple. Plse Help.

Using:
Apache OpenEJB 3.1.1    build: 20090530-06:18
EclipseLink 2.0.0
hsqldb 1.8.0

Thnking you anticipation

Regards

Mike
--
View this message in context: 
http://www.nabble.com/Embedded-OpenEJB-does-not-seem-to-be-flushing-to-the-DB-on-commit-tp25028791p25028791.html
Sent from the OpenEJB User mailing list archive at Nabble.com.



Reply via email to