Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » H2 Table Creation on glassfish startup(How can I get Eclipselink to create Tables for an in memory db everytime the container is started)
H2 Table Creation on glassfish startup [message #713445] Mon, 08 August 2011 13:34 Go to next message
J F is currently offline J F
Messages: 242
Registered: July 2009
Senior Member
Java 1.6b24
Eclipselink 2.2.0.v20110202-r8913
Glassfish 3.1

I am doing some testing using H2 under Glassfish with Eclipselink as the peristence provider.

When I deploy a new EAR with a new Persistence Unit Eclipselink creates the tables in my H2 Database. However when I restart glassfish without redeploying the app, the new tables are not created and the app fails with exceptions such as

org.h2.jdbc.JdbcSQLException: Table "LAZYSINGLETON" not found; SQL statement:
SELECT ID, LASTMAPINSTANCE, LASTSETINSTANCE, VERSION, MAPITEMS_ID, SETITEMS_ID FROM LAZYSINGLETON WHERE (ID = ?) [42102-154]


My peristence.xml is as follows;

<persistence-unit name="Experiment8memPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>Experiment8DBmem</jta-data-source>

<class>uk.co.his.experiment8.h2model.MapItem</class>
<class>uk.co.his.experiment8.h2model.SetItem</class>
<class>uk.co.his.experiment8.h2model.Singleton</class>
<class>uk.co.his.experiment8.h2model.lazy.LazyMapItem</class>
<class>uk.co.his.experiment8.h2model.lazy.LazyMap</class>
<class>uk.co.his.experiment8.h2model.lazy.LazySetItem</class>
<class>uk.co.his.experiment8.h2model.lazy.LazySet</class>
<class>uk.co.his.experiment8.h2model.lazy.LazySingleton</class>
<properties>
<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.H2Platform"/>
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:Experiment8DBmem"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
</properties>
</persistence-unit>

I have created the H2 DataSource using a glassfish-resource file ...

<jdbc-resource jndi-name="Experiment8DBmem" enabled="true" object-type="user" pool-name="Experiment8DBmemPool" />
<jdbc-connection-pool
datasource-classname="org.h2.jdbcx.JdbcDataSource"
name="Experiment8DBmemPool"
res-type="javax.sql.DataSource">
<property name="User" value="admin" />
<property name="Password" value="admin" />
<property name="URL" value="jdbc:h2:mem:Experiment8DBmem" />
<property name="driverClass" value="org.h2.Driver" />
<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.H2Platform /">
<property name="eclipselink.ddl-generation" value="create-tables"/>
</jdbc-connection-pool>
Re: H2 Table Creation on glassfish startup [message #713510 is a reply to message #713445] Mon, 08 August 2011 14:53 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

<property name="eclipselink.ddl-generation" value="create-tables"/>

Will cause the tables to be recreated when the persistence unit is first accessed. Glassfish is probably doing something odd, and changing this property. Glassfish does do some things with DDL to try to handle DDL changes between deployments.


James : Wiki : Book : Blog : Twitter
Re: H2 Table Creation on glassfish startup [message #713620 is a reply to message #713510] Mon, 08 August 2011 17:05 Go to previous messageGo to next message
J F is currently offline J F
Messages: 242
Registered: July 2009
Senior Member
Could I use a customizer to force this?
Re: H2 Table Creation on glassfish startup [message #714830 is a reply to message #713620] Thu, 11 August 2011 15:07 Go to previous message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

I would check with the Glassfish community to see what they are doing first.

You cannot affect this property in a SessionCustomizer, but you could force table creation in a customizer thorugh using the DefaultTableGenerator directly.


James : Wiki : Book : Blog : Twitter
Previous Topic:problems with historical sessions combined with @Version
Next Topic:TYPE() fails in projection query result: EclipseLink ConversionException
Goto Forum:
  


Current Time: Thu Oct 02 14:39:27 GMT 2014

Powered by FUDForum. Page generated in 0.02532 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software