users@glassfish.java.net

DataSourceDefinition and embedded Derby DB

From: Antonio Goncalves <antonio.mailing_at_gmail.com>
Date: Sat, 3 Dec 2011 21:57:24 +0100

Hi All,

I'm using DataSourceDefinition with CDI and Derby database. I use a utility
class to define a datasource and at the same time produce my entity manager
:

@DataSourceDefinition(name = "java:app/jdbc/myDS",
        className = "org.apache.derby.jdbc.ClientDataSource",
        portNumber = 1527,
        serverName = "localhost",
        databaseName = "myDB",
        user = "app",
        password = "app",
        properties = {"createDatabase=create"}
)
public class DatabaseResource {

    @Produces
    @PersistenceContext(unitName = "myPU")
    @MyDatabase
    private EntityManager em;

}

This works fine. For test purpose I want to use Derby in-memory database. I
changed the DataSourceDefinition to many different possibilities but can't
make it work :

@DataSourceDefinition(name = "java:app/jdbc/myDS",
        className = "org.apache.derby.jdbc.EmbeddedDriver",
        url = "jdbc:derby:memory",
        databaseName = "myDB",
        properties = {"createDatabase=create"}
)

I've changed the URL to different values, added user & pwd (just in case),
got rid of the databaseName attribute and added it to the URL.... but I
can't find the right syntax nor can I find any references on the web. In
the persistence.xml I have the following and it works, so I think it's a
matter of finding the right syntax :

<property name="javax.persistence.jdbc.driver"
value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="javax.persistence.jdbc.url"
value="jdbc:derby:memory:myDB;create=true"/>


Any idea ?

Thanks
Antonio Goncalves