You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Kalpa Welivitigoda <ca...@gmail.com> on 2014/07/20 20:14:47 UTC

Create H2 database even before adding records

Hi,

I am developing an application with H2 in memory database.

The issue is that the table is created only after I add a record. Before
that, if I search for a record it says that the table is not found. I want
to create the table at the time the application starts rather than waiting
for a record to be added. Is there any property that serves this
requirement.

Following is the content of persistence.xml,

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
    <persistence-unit name="rest-jpa">

<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
        <jta-data-source>java:/comp/env/jdbc/restDB</jta-data-source>
        <class>org.wso2.as.ee.Student</class>
        <properties>
            <property name="openjpa.jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>
        </properties>
    </persistence-unit>
</persistence>

I have the datasource defined in context.xml as follows,

<?xml version="1.0" encoding="UTF-8"?>
<Context>
    <Resource
            name="jdbc/restDb"
            auth="Container"
            type="javax.sql.DataSource"
            driverClassName="org.h2.Driver"
            url="jdbc:h2:mem:restDb"
            username="admin"
            password="admin"
            JtaManaged="true" />
</Context>


-- 
Best Regards,

Kalpa Welivitigoda
+94776509215
http://about.me/callkalpa

Re: Create H2 database even before adding records

Posted by Mauro Chi <ma...@gmail.com>.
Define datasourcece into tomee.xml into tomee/conf  or resources.xml into
web-inf dir of web application not  into
context.xml.

Set also JtaManaged true

Search referencecard for tomee
 Il 24/lug/2014 18:00 "Kalpa Welivitigoda" <ca...@gmail.com> ha scritto:

> It's apache-tomee-plus-1.6.0.2
>
> I have my data source defined in context.xml and persistence.xml refers it
> via JNDI.
>
> I present you briefly with my setup hoping it will help you to figure out
> what's wrong. I'll provide you with the source code if you want further
> analysis.
>
> I have the Order Entity. I have a separate class called OrderManager. It is
> a stateful bean which has a EntityManager through @PersistenceContext (with
> Extended as the persistence type). I have a servlet which processes the
> requests and it has a EJB (EntityManager) injected.
>
>
>
>
> On Thu, Jul 24, 2014 at 7:06 PM, Rick Curtis <cu...@gmail.com> wrote:
>
> > Hrmm, odd. What version of TomEE are you using?
> >
> >
> > On Thu, Jul 24, 2014 at 12:25 AM, Kalpa Welivitigoda <
> callkalpa@gmail.com>
> > wrote:
> >
> > > Well it worked for me for some reason which I don't know. Yes your
> point
> > is
> > > valid, it is a JPA 2.1 property and OpenJPA support JPA 2.0.
> > >
> > > I observed the following,
> > >
> > > Without any property set in persistence.xml, if I restart TomEE it
> works
> > as
> > > expected. However when I tried again the same process, it doesn't work
> > (it
> > > complains that the table doesn't exist). It is strange. If I redeploy
> the
> > > app (without any modifications) and try the functionality, it complains
> > > that the table doesn't exist.
> > >
> > >
> > >
> > >
> > > On Tue, Jul 22, 2014 at 6:37 PM, Rick Curtis <cu...@gmail.com>
> wrote:
> > >
> > > > > <property
> name="javax.persistence.schema-generation.database.action"
> > > > value="drop-and-create"></property> entry in persistence.xml worked
> for
> > > me.
> > > >
> > > > ... that doesn't make much sense to me. That property is a JPA 2.1
> spec
> > > > defined proeprty, and OpenJPA doesn't yet support that spec. Are you
> > sure
> > > > that you are really using OpenJPA? If you are using OpenJPA, I'm
> quite
> > > > certain that the openjpa.jdbc.SynchronizeMapping property is doing
> all
> > of
> > > > the work.
> > > >
> > > > Thanks,
> > > > Rick
> > > >
> > > >
> > > >
> > > > On Tue, Jul 22, 2014 at 12:11 AM, Kalpa Welivitigoda <
> > > callkalpa@gmail.com>
> > > > wrote:
> > > >
> > > > > <property
> name="javax.persistence.schema-generation.database.action"
> > > > > value="drop-and-create"></property> entry in persistence.xml worked
> > for
> > > > me.
> > > > > Since it is a in memory database and used temporary, dropping at
> the
> > > end
> > > > of
> > > > > the application ok for me.
> > > > >
> > > > >
> > > > > On Tue, Jul 22, 2014 at 12:40 AM, Rick Curtis <cu...@gmail.com>
> > > > wrote:
> > > > >
> > > > > > The configuration(openjpa.jdbc.SynchronizeMapping) you have
> > provided
> > > > > should
> > > > > > cause tables to be created the first time and EntityManager is
> > > created.
> > > > > >
> > > > > > Thanks,
> > > > > > Rick
> > > > > >
> > > > > >
> > > > > > On Sun, Jul 20, 2014 at 1:14 PM, Kalpa Welivitigoda <
> > > > callkalpa@gmail.com
> > > > > >
> > > > > > wrote:
> > > > > >
> > > > > > > Hi,
> > > > > > >
> > > > > > > I am developing an application with H2 in memory database.
> > > > > > >
> > > > > > > The issue is that the table is created only after I add a
> record.
> > > > > Before
> > > > > > > that, if I search for a record it says that the table is not
> > > found. I
> > > > > > want
> > > > > > > to create the table at the time the application starts rather
> > than
> > > > > > waiting
> > > > > > > for a record to be added. Is there any property that serves
> this
> > > > > > > requirement.
> > > > > > >
> > > > > > > Following is the content of persistence.xml,
> > > > > > >
> > > > > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > > > > <persistence xmlns="http://java.sun.com/xml/ns/persistence"
> > > > > > version="2.0">
> > > > > > >     <persistence-unit name="rest-jpa">
> > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> > > > > > >
> > > <jta-data-source>java:/comp/env/jdbc/restDB</jta-data-source>
> > > > > > >         <class>org.wso2.as.ee.Student</class>
> > > > > > >         <properties>
> > > > > > >             <property name="openjpa.jdbc.SynchronizeMappings"
> > > > > > > value="buildSchema(ForeignKeys=true)"/>
> > > > > > >         </properties>
> > > > > > >     </persistence-unit>
> > > > > > > </persistence>
> > > > > > >
> > > > > > > I have the datasource defined in context.xml as follows,
> > > > > > >
> > > > > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > > > > <Context>
> > > > > > >     <Resource
> > > > > > >             name="jdbc/restDb"
> > > > > > >             auth="Container"
> > > > > > >             type="javax.sql.DataSource"
> > > > > > >             driverClassName="org.h2.Driver"
> > > > > > >             url="jdbc:h2:mem:restDb"
> > > > > > >             username="admin"
> > > > > > >             password="admin"
> > > > > > >             JtaManaged="true" />
> > > > > > > </Context>
> > > > > > >
> > > > > > >
> > > > > > > --
> > > > > > > Best Regards,
> > > > > > >
> > > > > > > Kalpa Welivitigoda
> > > > > > > +94776509215
> > > > > > > http://about.me/callkalpa
> > > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > --
> > > > > > *Rick Curtis*
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Best Regards,
> > > > >
> > > > > Kalpa Welivitigoda
> > > > > +94776509215
> > > > > http://about.me/callkalpa
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > *Rick Curtis*
> > > >
> > >
> > >
> > >
> > > --
> > > Best Regards,
> > >
> > > Kalpa Welivitigoda
> > > +94776509215
> > > http://about.me/callkalpa
> > >
> >
> >
> >
> > --
> > *Rick Curtis*
> >
>
>
>
> --
> Best Regards,
>
> Kalpa Welivitigoda
> +94776509215
> http://about.me/callkalpa
>

Re: Create H2 database even before adding records

Posted by Kalpa Welivitigoda <ca...@gmail.com>.
It's apache-tomee-plus-1.6.0.2

I have my data source defined in context.xml and persistence.xml refers it
via JNDI.

I present you briefly with my setup hoping it will help you to figure out
what's wrong. I'll provide you with the source code if you want further
analysis.

I have the Order Entity. I have a separate class called OrderManager. It is
a stateful bean which has a EntityManager through @PersistenceContext (with
Extended as the persistence type). I have a servlet which processes the
requests and it has a EJB (EntityManager) injected.




On Thu, Jul 24, 2014 at 7:06 PM, Rick Curtis <cu...@gmail.com> wrote:

> Hrmm, odd. What version of TomEE are you using?
>
>
> On Thu, Jul 24, 2014 at 12:25 AM, Kalpa Welivitigoda <ca...@gmail.com>
> wrote:
>
> > Well it worked for me for some reason which I don't know. Yes your point
> is
> > valid, it is a JPA 2.1 property and OpenJPA support JPA 2.0.
> >
> > I observed the following,
> >
> > Without any property set in persistence.xml, if I restart TomEE it works
> as
> > expected. However when I tried again the same process, it doesn't work
> (it
> > complains that the table doesn't exist). It is strange. If I redeploy the
> > app (without any modifications) and try the functionality, it complains
> > that the table doesn't exist.
> >
> >
> >
> >
> > On Tue, Jul 22, 2014 at 6:37 PM, Rick Curtis <cu...@gmail.com> wrote:
> >
> > > > <property name="javax.persistence.schema-generation.database.action"
> > > value="drop-and-create"></property> entry in persistence.xml worked for
> > me.
> > >
> > > ... that doesn't make much sense to me. That property is a JPA 2.1 spec
> > > defined proeprty, and OpenJPA doesn't yet support that spec. Are you
> sure
> > > that you are really using OpenJPA? If you are using OpenJPA, I'm quite
> > > certain that the openjpa.jdbc.SynchronizeMapping property is doing all
> of
> > > the work.
> > >
> > > Thanks,
> > > Rick
> > >
> > >
> > >
> > > On Tue, Jul 22, 2014 at 12:11 AM, Kalpa Welivitigoda <
> > callkalpa@gmail.com>
> > > wrote:
> > >
> > > > <property name="javax.persistence.schema-generation.database.action"
> > > > value="drop-and-create"></property> entry in persistence.xml worked
> for
> > > me.
> > > > Since it is a in memory database and used temporary, dropping at the
> > end
> > > of
> > > > the application ok for me.
> > > >
> > > >
> > > > On Tue, Jul 22, 2014 at 12:40 AM, Rick Curtis <cu...@gmail.com>
> > > wrote:
> > > >
> > > > > The configuration(openjpa.jdbc.SynchronizeMapping) you have
> provided
> > > > should
> > > > > cause tables to be created the first time and EntityManager is
> > created.
> > > > >
> > > > > Thanks,
> > > > > Rick
> > > > >
> > > > >
> > > > > On Sun, Jul 20, 2014 at 1:14 PM, Kalpa Welivitigoda <
> > > callkalpa@gmail.com
> > > > >
> > > > > wrote:
> > > > >
> > > > > > Hi,
> > > > > >
> > > > > > I am developing an application with H2 in memory database.
> > > > > >
> > > > > > The issue is that the table is created only after I add a record.
> > > > Before
> > > > > > that, if I search for a record it says that the table is not
> > found. I
> > > > > want
> > > > > > to create the table at the time the application starts rather
> than
> > > > > waiting
> > > > > > for a record to be added. Is there any property that serves this
> > > > > > requirement.
> > > > > >
> > > > > > Following is the content of persistence.xml,
> > > > > >
> > > > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > > > <persistence xmlns="http://java.sun.com/xml/ns/persistence"
> > > > > version="2.0">
> > > > > >     <persistence-unit name="rest-jpa">
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> > > > > >
> > <jta-data-source>java:/comp/env/jdbc/restDB</jta-data-source>
> > > > > >         <class>org.wso2.as.ee.Student</class>
> > > > > >         <properties>
> > > > > >             <property name="openjpa.jdbc.SynchronizeMappings"
> > > > > > value="buildSchema(ForeignKeys=true)"/>
> > > > > >         </properties>
> > > > > >     </persistence-unit>
> > > > > > </persistence>
> > > > > >
> > > > > > I have the datasource defined in context.xml as follows,
> > > > > >
> > > > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > > > <Context>
> > > > > >     <Resource
> > > > > >             name="jdbc/restDb"
> > > > > >             auth="Container"
> > > > > >             type="javax.sql.DataSource"
> > > > > >             driverClassName="org.h2.Driver"
> > > > > >             url="jdbc:h2:mem:restDb"
> > > > > >             username="admin"
> > > > > >             password="admin"
> > > > > >             JtaManaged="true" />
> > > > > > </Context>
> > > > > >
> > > > > >
> > > > > > --
> > > > > > Best Regards,
> > > > > >
> > > > > > Kalpa Welivitigoda
> > > > > > +94776509215
> > > > > > http://about.me/callkalpa
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > *Rick Curtis*
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > Best Regards,
> > > >
> > > > Kalpa Welivitigoda
> > > > +94776509215
> > > > http://about.me/callkalpa
> > > >
> > >
> > >
> > >
> > > --
> > > *Rick Curtis*
> > >
> >
> >
> >
> > --
> > Best Regards,
> >
> > Kalpa Welivitigoda
> > +94776509215
> > http://about.me/callkalpa
> >
>
>
>
> --
> *Rick Curtis*
>



-- 
Best Regards,

Kalpa Welivitigoda
+94776509215
http://about.me/callkalpa

Re: Create H2 database even before adding records

Posted by Rick Curtis <cu...@gmail.com>.
Hrmm, odd. What version of TomEE are you using?


On Thu, Jul 24, 2014 at 12:25 AM, Kalpa Welivitigoda <ca...@gmail.com>
wrote:

> Well it worked for me for some reason which I don't know. Yes your point is
> valid, it is a JPA 2.1 property and OpenJPA support JPA 2.0.
>
> I observed the following,
>
> Without any property set in persistence.xml, if I restart TomEE it works as
> expected. However when I tried again the same process, it doesn't work (it
> complains that the table doesn't exist). It is strange. If I redeploy the
> app (without any modifications) and try the functionality, it complains
> that the table doesn't exist.
>
>
>
>
> On Tue, Jul 22, 2014 at 6:37 PM, Rick Curtis <cu...@gmail.com> wrote:
>
> > > <property name="javax.persistence.schema-generation.database.action"
> > value="drop-and-create"></property> entry in persistence.xml worked for
> me.
> >
> > ... that doesn't make much sense to me. That property is a JPA 2.1 spec
> > defined proeprty, and OpenJPA doesn't yet support that spec. Are you sure
> > that you are really using OpenJPA? If you are using OpenJPA, I'm quite
> > certain that the openjpa.jdbc.SynchronizeMapping property is doing all of
> > the work.
> >
> > Thanks,
> > Rick
> >
> >
> >
> > On Tue, Jul 22, 2014 at 12:11 AM, Kalpa Welivitigoda <
> callkalpa@gmail.com>
> > wrote:
> >
> > > <property name="javax.persistence.schema-generation.database.action"
> > > value="drop-and-create"></property> entry in persistence.xml worked for
> > me.
> > > Since it is a in memory database and used temporary, dropping at the
> end
> > of
> > > the application ok for me.
> > >
> > >
> > > On Tue, Jul 22, 2014 at 12:40 AM, Rick Curtis <cu...@gmail.com>
> > wrote:
> > >
> > > > The configuration(openjpa.jdbc.SynchronizeMapping) you have provided
> > > should
> > > > cause tables to be created the first time and EntityManager is
> created.
> > > >
> > > > Thanks,
> > > > Rick
> > > >
> > > >
> > > > On Sun, Jul 20, 2014 at 1:14 PM, Kalpa Welivitigoda <
> > callkalpa@gmail.com
> > > >
> > > > wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > I am developing an application with H2 in memory database.
> > > > >
> > > > > The issue is that the table is created only after I add a record.
> > > Before
> > > > > that, if I search for a record it says that the table is not
> found. I
> > > > want
> > > > > to create the table at the time the application starts rather than
> > > > waiting
> > > > > for a record to be added. Is there any property that serves this
> > > > > requirement.
> > > > >
> > > > > Following is the content of persistence.xml,
> > > > >
> > > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > > <persistence xmlns="http://java.sun.com/xml/ns/persistence"
> > > > version="2.0">
> > > > >     <persistence-unit name="rest-jpa">
> > > > >
> > > > >
> > > >
> > >
> >
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> > > > >
> <jta-data-source>java:/comp/env/jdbc/restDB</jta-data-source>
> > > > >         <class>org.wso2.as.ee.Student</class>
> > > > >         <properties>
> > > > >             <property name="openjpa.jdbc.SynchronizeMappings"
> > > > > value="buildSchema(ForeignKeys=true)"/>
> > > > >         </properties>
> > > > >     </persistence-unit>
> > > > > </persistence>
> > > > >
> > > > > I have the datasource defined in context.xml as follows,
> > > > >
> > > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > > <Context>
> > > > >     <Resource
> > > > >             name="jdbc/restDb"
> > > > >             auth="Container"
> > > > >             type="javax.sql.DataSource"
> > > > >             driverClassName="org.h2.Driver"
> > > > >             url="jdbc:h2:mem:restDb"
> > > > >             username="admin"
> > > > >             password="admin"
> > > > >             JtaManaged="true" />
> > > > > </Context>
> > > > >
> > > > >
> > > > > --
> > > > > Best Regards,
> > > > >
> > > > > Kalpa Welivitigoda
> > > > > +94776509215
> > > > > http://about.me/callkalpa
> > > > >
> > > >
> > > >
> > > >
> > > > --
> > > > *Rick Curtis*
> > > >
> > >
> > >
> > >
> > > --
> > > Best Regards,
> > >
> > > Kalpa Welivitigoda
> > > +94776509215
> > > http://about.me/callkalpa
> > >
> >
> >
> >
> > --
> > *Rick Curtis*
> >
>
>
>
> --
> Best Regards,
>
> Kalpa Welivitigoda
> +94776509215
> http://about.me/callkalpa
>



-- 
*Rick Curtis*

Re: Create H2 database even before adding records

Posted by Kalpa Welivitigoda <ca...@gmail.com>.
Well it worked for me for some reason which I don't know. Yes your point is
valid, it is a JPA 2.1 property and OpenJPA support JPA 2.0.

I observed the following,

Without any property set in persistence.xml, if I restart TomEE it works as
expected. However when I tried again the same process, it doesn't work (it
complains that the table doesn't exist). It is strange. If I redeploy the
app (without any modifications) and try the functionality, it complains
that the table doesn't exist.




On Tue, Jul 22, 2014 at 6:37 PM, Rick Curtis <cu...@gmail.com> wrote:

> > <property name="javax.persistence.schema-generation.database.action"
> value="drop-and-create"></property> entry in persistence.xml worked for me.
>
> ... that doesn't make much sense to me. That property is a JPA 2.1 spec
> defined proeprty, and OpenJPA doesn't yet support that spec. Are you sure
> that you are really using OpenJPA? If you are using OpenJPA, I'm quite
> certain that the openjpa.jdbc.SynchronizeMapping property is doing all of
> the work.
>
> Thanks,
> Rick
>
>
>
> On Tue, Jul 22, 2014 at 12:11 AM, Kalpa Welivitigoda <ca...@gmail.com>
> wrote:
>
> > <property name="javax.persistence.schema-generation.database.action"
> > value="drop-and-create"></property> entry in persistence.xml worked for
> me.
> > Since it is a in memory database and used temporary, dropping at the end
> of
> > the application ok for me.
> >
> >
> > On Tue, Jul 22, 2014 at 12:40 AM, Rick Curtis <cu...@gmail.com>
> wrote:
> >
> > > The configuration(openjpa.jdbc.SynchronizeMapping) you have provided
> > should
> > > cause tables to be created the first time and EntityManager is created.
> > >
> > > Thanks,
> > > Rick
> > >
> > >
> > > On Sun, Jul 20, 2014 at 1:14 PM, Kalpa Welivitigoda <
> callkalpa@gmail.com
> > >
> > > wrote:
> > >
> > > > Hi,
> > > >
> > > > I am developing an application with H2 in memory database.
> > > >
> > > > The issue is that the table is created only after I add a record.
> > Before
> > > > that, if I search for a record it says that the table is not found. I
> > > want
> > > > to create the table at the time the application starts rather than
> > > waiting
> > > > for a record to be added. Is there any property that serves this
> > > > requirement.
> > > >
> > > > Following is the content of persistence.xml,
> > > >
> > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > <persistence xmlns="http://java.sun.com/xml/ns/persistence"
> > > version="2.0">
> > > >     <persistence-unit name="rest-jpa">
> > > >
> > > >
> > >
> >
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> > > >         <jta-data-source>java:/comp/env/jdbc/restDB</jta-data-source>
> > > >         <class>org.wso2.as.ee.Student</class>
> > > >         <properties>
> > > >             <property name="openjpa.jdbc.SynchronizeMappings"
> > > > value="buildSchema(ForeignKeys=true)"/>
> > > >         </properties>
> > > >     </persistence-unit>
> > > > </persistence>
> > > >
> > > > I have the datasource defined in context.xml as follows,
> > > >
> > > > <?xml version="1.0" encoding="UTF-8"?>
> > > > <Context>
> > > >     <Resource
> > > >             name="jdbc/restDb"
> > > >             auth="Container"
> > > >             type="javax.sql.DataSource"
> > > >             driverClassName="org.h2.Driver"
> > > >             url="jdbc:h2:mem:restDb"
> > > >             username="admin"
> > > >             password="admin"
> > > >             JtaManaged="true" />
> > > > </Context>
> > > >
> > > >
> > > > --
> > > > Best Regards,
> > > >
> > > > Kalpa Welivitigoda
> > > > +94776509215
> > > > http://about.me/callkalpa
> > > >
> > >
> > >
> > >
> > > --
> > > *Rick Curtis*
> > >
> >
> >
> >
> > --
> > Best Regards,
> >
> > Kalpa Welivitigoda
> > +94776509215
> > http://about.me/callkalpa
> >
>
>
>
> --
> *Rick Curtis*
>



-- 
Best Regards,

Kalpa Welivitigoda
+94776509215
http://about.me/callkalpa

Re: Create H2 database even before adding records

Posted by Rick Curtis <cu...@gmail.com>.
> <property name="javax.persistence.schema-generation.database.action"
value="drop-and-create"></property> entry in persistence.xml worked for me.

... that doesn't make much sense to me. That property is a JPA 2.1 spec
defined proeprty, and OpenJPA doesn't yet support that spec. Are you sure
that you are really using OpenJPA? If you are using OpenJPA, I'm quite
certain that the openjpa.jdbc.SynchronizeMapping property is doing all of
the work.

Thanks,
Rick



On Tue, Jul 22, 2014 at 12:11 AM, Kalpa Welivitigoda <ca...@gmail.com>
wrote:

> <property name="javax.persistence.schema-generation.database.action"
> value="drop-and-create"></property> entry in persistence.xml worked for me.
> Since it is a in memory database and used temporary, dropping at the end of
> the application ok for me.
>
>
> On Tue, Jul 22, 2014 at 12:40 AM, Rick Curtis <cu...@gmail.com> wrote:
>
> > The configuration(openjpa.jdbc.SynchronizeMapping) you have provided
> should
> > cause tables to be created the first time and EntityManager is created.
> >
> > Thanks,
> > Rick
> >
> >
> > On Sun, Jul 20, 2014 at 1:14 PM, Kalpa Welivitigoda <callkalpa@gmail.com
> >
> > wrote:
> >
> > > Hi,
> > >
> > > I am developing an application with H2 in memory database.
> > >
> > > The issue is that the table is created only after I add a record.
> Before
> > > that, if I search for a record it says that the table is not found. I
> > want
> > > to create the table at the time the application starts rather than
> > waiting
> > > for a record to be added. Is there any property that serves this
> > > requirement.
> > >
> > > Following is the content of persistence.xml,
> > >
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <persistence xmlns="http://java.sun.com/xml/ns/persistence"
> > version="2.0">
> > >     <persistence-unit name="rest-jpa">
> > >
> > >
> >
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> > >         <jta-data-source>java:/comp/env/jdbc/restDB</jta-data-source>
> > >         <class>org.wso2.as.ee.Student</class>
> > >         <properties>
> > >             <property name="openjpa.jdbc.SynchronizeMappings"
> > > value="buildSchema(ForeignKeys=true)"/>
> > >         </properties>
> > >     </persistence-unit>
> > > </persistence>
> > >
> > > I have the datasource defined in context.xml as follows,
> > >
> > > <?xml version="1.0" encoding="UTF-8"?>
> > > <Context>
> > >     <Resource
> > >             name="jdbc/restDb"
> > >             auth="Container"
> > >             type="javax.sql.DataSource"
> > >             driverClassName="org.h2.Driver"
> > >             url="jdbc:h2:mem:restDb"
> > >             username="admin"
> > >             password="admin"
> > >             JtaManaged="true" />
> > > </Context>
> > >
> > >
> > > --
> > > Best Regards,
> > >
> > > Kalpa Welivitigoda
> > > +94776509215
> > > http://about.me/callkalpa
> > >
> >
> >
> >
> > --
> > *Rick Curtis*
> >
>
>
>
> --
> Best Regards,
>
> Kalpa Welivitigoda
> +94776509215
> http://about.me/callkalpa
>



-- 
*Rick Curtis*

Re: Create H2 database even before adding records

Posted by Kalpa Welivitigoda <ca...@gmail.com>.
<property name="javax.persistence.schema-generation.database.action"
value="drop-and-create"></property> entry in persistence.xml worked for me.
Since it is a in memory database and used temporary, dropping at the end of
the application ok for me.


On Tue, Jul 22, 2014 at 12:40 AM, Rick Curtis <cu...@gmail.com> wrote:

> The configuration(openjpa.jdbc.SynchronizeMapping) you have provided should
> cause tables to be created the first time and EntityManager is created.
>
> Thanks,
> Rick
>
>
> On Sun, Jul 20, 2014 at 1:14 PM, Kalpa Welivitigoda <ca...@gmail.com>
> wrote:
>
> > Hi,
> >
> > I am developing an application with H2 in memory database.
> >
> > The issue is that the table is created only after I add a record. Before
> > that, if I search for a record it says that the table is not found. I
> want
> > to create the table at the time the application starts rather than
> waiting
> > for a record to be added. Is there any property that serves this
> > requirement.
> >
> > Following is the content of persistence.xml,
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <persistence xmlns="http://java.sun.com/xml/ns/persistence"
> version="2.0">
> >     <persistence-unit name="rest-jpa">
> >
> >
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> >         <jta-data-source>java:/comp/env/jdbc/restDB</jta-data-source>
> >         <class>org.wso2.as.ee.Student</class>
> >         <properties>
> >             <property name="openjpa.jdbc.SynchronizeMappings"
> > value="buildSchema(ForeignKeys=true)"/>
> >         </properties>
> >     </persistence-unit>
> > </persistence>
> >
> > I have the datasource defined in context.xml as follows,
> >
> > <?xml version="1.0" encoding="UTF-8"?>
> > <Context>
> >     <Resource
> >             name="jdbc/restDb"
> >             auth="Container"
> >             type="javax.sql.DataSource"
> >             driverClassName="org.h2.Driver"
> >             url="jdbc:h2:mem:restDb"
> >             username="admin"
> >             password="admin"
> >             JtaManaged="true" />
> > </Context>
> >
> >
> > --
> > Best Regards,
> >
> > Kalpa Welivitigoda
> > +94776509215
> > http://about.me/callkalpa
> >
>
>
>
> --
> *Rick Curtis*
>



-- 
Best Regards,

Kalpa Welivitigoda
+94776509215
http://about.me/callkalpa

Re: Create H2 database even before adding records

Posted by Rick Curtis <cu...@gmail.com>.
The configuration(openjpa.jdbc.SynchronizeMapping) you have provided should
cause tables to be created the first time and EntityManager is created.

Thanks,
Rick


On Sun, Jul 20, 2014 at 1:14 PM, Kalpa Welivitigoda <ca...@gmail.com>
wrote:

> Hi,
>
> I am developing an application with H2 in memory database.
>
> The issue is that the table is created only after I add a record. Before
> that, if I search for a record it says that the table is not found. I want
> to create the table at the time the application starts rather than waiting
> for a record to be added. Is there any property that serves this
> requirement.
>
> Following is the content of persistence.xml,
>
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="2.0">
>     <persistence-unit name="rest-jpa">
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>         <jta-data-source>java:/comp/env/jdbc/restDB</jta-data-source>
>         <class>org.wso2.as.ee.Student</class>
>         <properties>
>             <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema(ForeignKeys=true)"/>
>         </properties>
>     </persistence-unit>
> </persistence>
>
> I have the datasource defined in context.xml as follows,
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Context>
>     <Resource
>             name="jdbc/restDb"
>             auth="Container"
>             type="javax.sql.DataSource"
>             driverClassName="org.h2.Driver"
>             url="jdbc:h2:mem:restDb"
>             username="admin"
>             password="admin"
>             JtaManaged="true" />
> </Context>
>
>
> --
> Best Regards,
>
> Kalpa Welivitigoda
> +94776509215
> http://about.me/callkalpa
>



-- 
*Rick Curtis*