Take a look at the data source example, which uses hsql. It should work with 
any db though. - John

________________________________

From: Vincenzo [mailto:[email protected]]
Sent: Thu 10/28/2010 8:08 AM
To: [email protected]
Subject: How to override my persistence unit entirely?




Hi all,

I've posted this question on stackoverflow, but got no answer yet
(http://stackoverflow.com/questions/4042232). Please, help me here:

This is my SLSB:

    @Stateless
    public class MyService {
      PersistenceContext(unitName = "abc")
      EntityManager em;
      public boolean exists(int id) {
        return this.em.find(Employee.class, id) != null;
      }
    }

This is my `persistence.xml` (I'm using Glassfish v3):

    <persistence>
      <persistence-unit name="abc">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <jta-data-source>java:/MyDS</jta-data-source>
        <properties>
            <property name="hibernate.archive.autodetection" value="class"
/>
            <property name="hibernate.dialect"
              value="org.hibernate.dialect.MySQLInnoDBDialect" />
        </properties>
      </persistence-unit>
    </persistence>

Now I'm trying to create a test, using OpenEJB embedded container. This is
my test class:

    class MyServiceText {
      @Test
      public void testChecksExistence() throws Exception {
        Properties properties = new Properties();
        properties.setProperty(
            javax.naming.Context.INITIAL_CONTEXT_FACTORY,
            "org.apache.openejb.client.LocalInitialContextFactory"
        );
        InitialContext ic = new InitialContext(properties);
        // actual testing skipped
      }
    }

I would like to use HSQL for testing. How can I instruct OpenEJB that my
persistence unit `"abc"` has to point to HSQL during testing? Shall I create
a new version of `persistence.xml`? Shall I use `openejb.xml`? I'm lost in
examples
(http://openejb.apache.org/3.0/configuring-persistenceunits-in-tests.html)..
:(

It's a Maven-3 project.

Thanks!
--
View this message in context: 
http://openejb.979440.n4.nabble.com/How-to-override-my-persistence-unit-entirely-tp3017067p3017067.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Reply via email to