You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Lu Jiang <je...@gmail.com> on 2010/08/05 13:13:32 UTC

Does OPENJPA support to generate table automatically?

Hi,all

    I am a newbie to OPENJPA.
    Currently I am trying to create a project which uses JPA 2.0 new
features like @Embedded,Map<Key,Value>,List<Embedded class>, I have
created a few entity classes which is annotated with @Entity.
    The table structure and relationship seem to be a bit
complicated..In order to avoid any mistake when creating tables
manually,I wander is it possible to configure something in
persistence.xml,then all the tables will be automatically created by
OPENJPA according to each entity class?

Re: Does OPENJPA support to generate table automatically?

Posted by idan <id...@gmail.com>.
No problem :-)

-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Does-OPENJPA-support-to-generate-table-automatically-tp5376084p5386080.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Does OPENJPA support to generate table automatically?

Posted by Lu Jiang <je...@gmail.com>.
Finally,after a few trials,the tables are generated automatically by OPENJPA.
idan,thanks again for your suggestion!That works!

Re: Does OPENJPA support to generate table automatically?

Posted by Lu Jiang <je...@gmail.com>.
Hi,idan

Thanks a lot to your quick reply.
But I still got some problem when inserting data into the table.
The exception is as following:

Exception in thread "main" <openjpa-2.0.0-r422266:935683 fatal store
error> org.apache.openjpa.persistence.RollbackException: The
transaction has been rolled back.  See the nested exceptions for
details on the errors that occurred.
        at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:583)
        at org.apache.geronimo.sample.jpa20.bean.CourseFacade.create(CourseFacade.java:33)
        at org.apahce.geronimo.sample.jpa20.test.test.main(test.java:40)
Caused by: <openjpa-2.0.0-r422266:935683 fatal general error>
org.apache.openjpa.persistence.PersistenceException: The transaction
has been rolled back.  See the nested exceptions for details on the
errors that occurred.
        at org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2302)
        at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2139)
        at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2037)
        at org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1955)
        at org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81)
        at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1479)
        at org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:925)
        at org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:559)
        ... 2 more
Caused by: <openjpa-2.0.0-r422266:935683 fatal general error>
org.apache.openjpa.persistence.PersistenceException: Table/View"
COURSE" doesn't exist。 {INSERT INTO Course (cid, assistTeacher,
classroom, cname, teacher) VALUES (?, ?, ?, ?, ?)} [code=-1,
state=42X05]
        at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4827)
        at org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4787)
        at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:136)
        at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:110)
        at org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:62)
        at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:89)
        at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:550)
        at org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:106)
        at org.apache.openjpa.jdbc.kernel.BatchingConstraintUpdateManager.flush(BatchingConstraintUpdateManager.java:59)
        at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:103)
        at org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:76)
        at org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:751)
        at org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:131)
        ... 9 more
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException:
Table/View " COURSE" doesn't exist。 {INSERT INTO Course (cid,
assistTeacher, classroom, cname, teacher) VALUES (?, ?, ?, ?, ?)}
[code=-1, state=42X05]
        at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:257)
        at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:237)
        at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$000(LoggingConnectionDecorator.java:70)
        at org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection.prepareStatement(LoggingConnectionDecorator.java:289)
        at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:186)
        at org.apache.openjpa.lib.jdbc.ConfiguringConnectionDecorator$ConfiguringConnection.prepareStatement(ConfiguringConnectionDecorator.java:155)
        at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:186)
        at org.apache.openjpa.jdbc.kernel.JDBCStoreManager$RefCountConnection.prepareStatement(JDBCStoreManager.java:1664)
        at org.apache.openjpa.lib.jdbc.DelegatingConnection.prepareStatement(DelegatingConnection.java:175)
        at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.prepareStatement(PreparedStatementManagerImpl.java:289)
        at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushAndUpdate(PreparedStatementManagerImpl.java:112)
        at org.apache.openjpa.jdbc.kernel.BatchingPreparedStatementManagerImpl.flushAndUpdate(BatchingPreparedStatementManagerImpl.java:81)
        at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:99)
        at org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:87)
        ... 16 more
Java Result: 1

Could someone help to give me some hint?

2010/8/5 idan <id...@gmail.com>:
>
> In your persistence.xml file, under the relevant <persistenence-unit>
> You can set this property:
>
>        <property name="jdbc.SynchronizeMappings"
> value="buildSchema(ForeignKeys=true)"/>
>
> You can read more about it here:
> http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/ref_guide_conf_jdbc.html#openjpa.jdbc.SynchronizeMappings
> http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/ref_guide_conf_jdbc.html#openjpa.jdbc.SynchronizeMappings
> --
> View this message in context: http://openjpa.208410.n2.nabble.com/Does-OPENJPA-support-to-generate-table-automatically-tp5376084p5376576.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Re: Does OPENJPA support to generate table automatically?

Posted by idan <id...@gmail.com>.
In your persistence.xml file, under the relevant <persistenence-unit>
You can set this property:

	<property name="jdbc.SynchronizeMappings"
value="buildSchema(ForeignKeys=true)"/>

You can read more about it here:
http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/ref_guide_conf_jdbc.html#openjpa.jdbc.SynchronizeMappings
http://openjpa.apache.org/builds/1.0.2/apache-openjpa-1.0.2/docs/manual/ref_guide_conf_jdbc.html#openjpa.jdbc.SynchronizeMappings 
-- 
View this message in context: http://openjpa.208410.n2.nabble.com/Does-OPENJPA-support-to-generate-table-automatically-tp5376084p5376576.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.