You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Bernhard Humm <b....@fbi.h-da.de> on 2008/10/20 17:11:47 UTC

Inspect database when using embedded OpenEJB

Dear all,

when using OpenEJB embedded in JUnit tests are entity beans actually being
persisted to disk? 
Is there a way of inspecting the database content after execution of the
JUnit tests?
I am using NetBeans IDE. Can I use the built-in database viewer to connect
to the database? How do I specify the connect parameters?

Best regards
        Bernhard
-- 
View this message in context: http://www.nabble.com/Inspect-database-when-using-embedded-OpenEJB-tp20071160p20071160.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Inspect database when using embedded OpenEJB

Posted by David Blevins <da...@visi.com>.
On Oct 29, 2008, at 3:58 AM, Bernhard Humm wrote:

> thanks a lot for your response. I have installed the new release.  
> However, I
> still can't find database values on disk. All JUnit test cases that  
> create
> and retrieve entity beans run fine (OpenEJB is really a great  
> product :-)).
> In my NetBeans project there is a path with HSQL database files:
> C:\temp\NetBeans\LibraryX\tmp\testing\data\hsqldb\hsqldb.*
> However, after running the test cases, the files don't seem to be  
> touched
> (old file date). I can connet to this database from the NetBeans  
> database
> viewer:
> Database URL:
> jdbc:hsqldb:file:/temp/NetBeans/LibraryX/tmp/testing/data/hsqldb/ 
> hsqldb
> Driver	: org.hsqldb.jdbcDriver
> Schema:	PUBLIC
> Product:	HSQL Database Engine
> User:	sa
> Password: ""
> Database product name: 	HSQL Database Engine
> Database product version:	1.8.0
>
> However, there are no current values.
> To my surpise, the database contained tables and values from earlier  
> tests.
> But the values were not updated by current tests. After deleting the  
> tables,
> they were not re-created.

If there were values from older tests that's a good sign.  Figuring  
out why new updates aren't showing up may be a process of  
elimination.  I suspect that the issue may be what I mentioned  
previously that I'm not sure more than one VM (i.e. more than on  
"hsql") can be using the HSQL database files at the same time.   So if  
the Netbeans database viewer is running while the test is running,  
that might be the issue.

One simple test would be to write a test case that uses the  
java.sql.DriverManager and JDBC directly to add and update a table  
(any made up table), then see if you can see it in the NetBeans  
database viewer.

-David


Re: Inspect database when using embedded OpenEJB

Posted by Bernhard Humm <b....@fbi.h-da.de>.


David Blevins wrote:
> 
> 
> ...
> 
> Wanted to respond to this earlier, but was swamped with finalizing the  
> release.  Anyway, it's up now.  Give it a try and hopefully things work.
> 
> If not post some config details and maybe we can spot something.
> 
> -David
> 
> 

Dear David,

thanks a lot for your response. I have installed the new release. However, I
still can't find database values on disk. All JUnit test cases that create
and retrieve entity beans run fine (OpenEJB is really a great product :-)). 
In my NetBeans project there is a path with HSQL database files:
C:\temp\NetBeans\LibraryX\tmp\testing\data\hsqldb\hsqldb.*
However, after running the test cases, the files don't seem to be touched
(old file date). I can connet to this database from the NetBeans database
viewer:
Database URL:
jdbc:hsqldb:file:/temp/NetBeans/LibraryX/tmp/testing/data/hsqldb/hsqldb
Driver	: org.hsqldb.jdbcDriver
Schema:	PUBLIC
Product:	HSQL Database Engine
User:	sa
Password: ""
Database product name: 	HSQL Database Engine
Database product version:	1.8.0

However, there are no current values.
To my surpise, the database contained tables and values from earlier tests.
But the values were not updated by current tests. After deleting the tables,
they were not re-created.

This is the content of my persistence.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
  <persistence-unit name="libraryX-unit">
   
<jta-data-source>java:openejb/Resource/libraryXDatabase</jta-data-source>
    <properties>
      <property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
    </properties>
  </persistence-unit>
</persistence>

Regards
   Bernhard
-- 
View this message in context: http://www.nabble.com/Inspect-database-when-using-embedded-OpenEJB-tp20071160p20224695.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Inspect database when using embedded OpenEJB

Posted by David Blevins <da...@visi.com>.
On Oct 22, 2008, at 3:15 AM, Bernhard Humm wrote:

>
>
>
> David Blevins wrote:
>>
>>
>> In OpenEJB 3.0, when using the supplied HSQL datasource in a TestCase
>> we should be using an in memory database with the JdbcUrl of
>> "jdbc:hsqldb:mem:hsqldb".  In OpenEJB 3.0 that sometimes worked and
>> sometimes didn't (depending on if you had a conf/ directory in your
>> openejb.base path), in which case the files were written to disk and
>> the JdbcUrl ended up as "jdbc:hsqldb:file:data/hsqldb/hsqldb" which
>> would be relative to your openejb.base path as in "${openejb.base}/
>> data/hsqldb/hsqldb".
>>
>> In OpenEJB 3.1 we have a better way of detecting when we are running
>> embedded and the JdbcUrl will always be "jdbc:hsqldb:mem:hsqldb"
>> unless explicitly changed.
>>
>> ...
>>
>>
>
> Dear David,
>
> thank you for your detailed answer. However, it indeed does not work  
> with
> OpenEJB 3.0 in my case. Is there a way of getting OpenEJB 3.1 to test
> whether it works with the new release?

Wanted to respond to this earlier, but was swamped with finalizing the  
release.  Anyway, it's up now.  Give it a try and hopefully things work.

If not post some config details and maybe we can spot something.

-David


Re: Inspect database when using embedded OpenEJB

Posted by Bernhard Humm <b....@fbi.h-da.de>.


David Blevins wrote:
> 
> 
> In OpenEJB 3.0, when using the supplied HSQL datasource in a TestCase  
> we should be using an in memory database with the JdbcUrl of  
> "jdbc:hsqldb:mem:hsqldb".  In OpenEJB 3.0 that sometimes worked and  
> sometimes didn't (depending on if you had a conf/ directory in your  
> openejb.base path), in which case the files were written to disk and  
> the JdbcUrl ended up as "jdbc:hsqldb:file:data/hsqldb/hsqldb" which  
> would be relative to your openejb.base path as in "${openejb.base}/ 
> data/hsqldb/hsqldb".
> 
> In OpenEJB 3.1 we have a better way of detecting when we are running  
> embedded and the JdbcUrl will always be "jdbc:hsqldb:mem:hsqldb"  
> unless explicitly changed.
> 
> ...
> 
> 

Dear David,

thank you for your detailed answer. However, it indeed does not work with
OpenEJB 3.0 in my case. Is there a way of getting OpenEJB 3.1 to test
whether it works with the new release?

Regards
        Bernhard

-- 
View this message in context: http://www.nabble.com/Inspect-database-when-using-embedded-OpenEJB-tp20071160p20107772.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: Inspect database when using embedded OpenEJB

Posted by David Blevins <da...@visi.com>.
On Oct 20, 2008, at 8:11 AM, Bernhard Humm wrote:

>
> Dear all,
>
> when using OpenEJB embedded in JUnit tests are entity beans actually  
> being
> persisted to disk?
> Is there a way of inspecting the database content after execution of  
> the
> JUnit tests?
> I am using NetBeans IDE. Can I use the built-in database viewer to  
> connect
> to the database? How do I specify the connect parameters?

In OpenEJB 3.0, when using the supplied HSQL datasource in a TestCase  
we should be using an in memory database with the JdbcUrl of  
"jdbc:hsqldb:mem:hsqldb".  In OpenEJB 3.0 that sometimes worked and  
sometimes didn't (depending on if you had a conf/ directory in your  
openejb.base path), in which case the files were written to disk and  
the JdbcUrl ended up as "jdbc:hsqldb:file:data/hsqldb/hsqldb" which  
would be relative to your openejb.base path as in "${openejb.base}/ 
data/hsqldb/hsqldb".

In OpenEJB 3.1 we have a better way of detecting when we are running  
embedded and the JdbcUrl will always be "jdbc:hsqldb:mem:hsqldb"  
unless explicitly changed.

You should be able to use the NetBeans IDE tooling to connect to the  
database of the file based HSQLDB, in which case I recommend you  
explicitly supply the absolute path of the database files in your  
JdbcUrl and explicitly supply all data source parameters to both  
OpenEJB an NetBeans to ensure that they are the same.

Here might be some good values for both:

     JdbcDriver  org.hsqldb.jdbcDriver
     JdbcUrl     jdbc:hsqldb:file:/tmp/testing/data/hsqldb/hsqldb
     UserName    sa
     Password

On the OpenEJB side when embedding, you can explicitly declare a  
datasource and all parameters right in the test case as follows:

     Properties p = new Properties();
     p.put(Context.INITIAL_CONTEXT_FACTORY,  
"org.apache.openejb.client.LocalInitialContextFactory");
     p.put("movieDatabase", "new://Resource?type=DataSource");
     p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
     p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:file:/tmp/testing/ 
data/hsqldb/hsqldb");
     p.put("movieDatabase.UserName", "sa");
     p.put("movieDatabase.Password", "");
     InitialContext context = new InitialContext(p);

Not sure how the data is supplied to NetBeans IDE.

Note that I don't think HSQLDB will allow more than one VM to be  
connected to the database files at one time, so be ready to get some  
exceptions if you attempt to use both simultaneously.  If that becomes  
a pain, you can set HSQLDB up as a standalone database as per the  
documentation on their side rather than using it as an embedded  
database.  You would just need to adjust your JdbcUrl accordingly in  
both OpenEJB and NetBeans.

-David