Hi Patrick,
> By "JPA auto strategy", I'm assuming that you mean @GeneratedValue
> with no specified strategy, which defaults to GenerationType.AUTO.
I mean, if I do not provide "@GeneratedValue(strategy =
GenerationType.IDENTITY)", then I get errors. I'd prefer not to
specify an @GeneratedValue tag at all.
> In OpenJPA, I believe that this translates to the same behavior as
> GenerationType.TABLE. What sorts of problems are you seeing with this
> strategy?
Below please see a stack trace from trying to persist the 2nd of two
simple entities. They have 3 fields: (id INTEGER PRIMARY KEY, created
TIMESTAMP, message TEXT).
Again, I am trying to make OpenJPA work on top of SQLiteJDBC.
These errors disappear if I add the GenerationType.IDENTITY to the @Id column.
Thanks for any help
-Marc
$ sh ./target/appassembler/bin/openjpa-testapp
Exception in thread "main" <openjpa-1.0.0-r420667:568756 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:419)
at
com.leadgenllc.testapp.openjpa.OpenJPATestApp.main(OpenJPATestApp.java:50)
Caused by: <openjpa-1.0.0-r420667:568756 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:2099)
at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1946)
at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1844)
at
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1762)
at
org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:81)
at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1292)
at
org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:861)
at
org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:408)
... 1 more
Caused by: <openjpa-1.0.0-r420667:568756 nonfatal general error>
org.apache.openjpa.persistence.PersistenceException: PRIMARY KEY must
be unique {prepstmnt 3524528 INSERT INTO Message (id, created,
message) VALUES (?, ?, ?) [params=(long) 0, (Timestamp) 2007-10-29
15:42:53.46, (String) Number Two!]} [code=0, state=null]
FailedObject: [EMAIL PROTECTED]
at
org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:3849)
at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:97)
at
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:67)
at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:108)
at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:73)
at
org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:543)
at
org.apache.openjpa.jdbc.kernel.ConstraintUpdateManager.flush(ConstraintUpdateManager.java:105)
at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:89)
at
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:72)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:514)
at
org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:130)
... 8 more
Caused by: org.apache.openjpa.lib.jdbc.ReportingSQLException: PRIMARY
KEY must be unique {prepstmnt 3524528 INSERT INTO Message (id,
created, message) VALUES (?, ?, ?) [params=(long) 0, (Timestamp)
2007-10-29 15:42:53.46, (String) Number Two!]} [code=0, state=null]
at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.wrap(LoggingConnectionDecorator.java:192)
at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator.access$800(LoggingConnectionDecorator.java:57)
at
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.executeUpdate(LoggingConnectionDecorator.java:858)
at
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:269)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager$CancelPreparedStatement.executeUpdate(JDBCStoreManager.java:1363)
at
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:97)
... 15 more
marc-siegels-computer:~/belvedere/maven/joe-testapp mlsiegel$
On 10/29/07, Patrick Linskey <[EMAIL PROTECTED]> wrote:
> Hi,
>
> By "JPA auto strategy", I'm assuming that you mean @GeneratedValue
> with no specified strategy, which defaults to GenerationType.AUTO.
>
> In OpenJPA, I believe that this translates to the same behavior as
> GenerationType.TABLE. What sorts of problems are you seeing with this
> strategy?
>
> -Patrick
>
> On 10/29/07, Marc Siegel <[EMAIL PROTECTED]> wrote:
> > Since I posted that mail, I looked through the source code of
> > DBDictionary, and as a result of that I the SQLiteDictionary to have
> > lastGeneratedKeyQuery = "SELECT MAX({0}) FROM {1}";
> >
> > My mapping is simply any class with an @Id column. I have succeeded in
> > making this work by adding @GeneratedValue(strategy =
> > GenerationType.IDENTITY), but would like to be able to make this work
> > with the JPA auto strategy as well.
> >
> > Thanks
> > -Marc
> >
> > On 10/28/07, Patrick Linskey <[EMAIL PROTECTED]> wrote:
> > > Hi,
> > >
> > > What does your mapping look like for your class?
> > >
> > > -Patrick
> > >
> > > On 10/26/07, Marc Siegel <[EMAIL PROTECTED]> wrote:
> > > > Hi folks,
> > > >
> > > > I am trying to user OpenJPA 1.0.0 on top of SQLiteJDBC.
> > > > OpenJPA wants to insert an Id if zero for every row.
> > > >
> > > > I know I need a DBDictionary subclass, I have tried making one with
> > > > - createPrimaryKey = false
> > > > - lastGeneratedKeyQuery = "SELECT SEQ FROM SQLITE_SEQUENCE WHERE
> > > > NAME = \"{0}\"";
> > > >
> > > > Neither of these worked. Any knowledgable suggestions?
> > > >
> > > > Many thanks,
> > > > -Marc
> > > >
> > >
> > >
> > > --
> > > Patrick Linskey
> > > 202 669 5907
> > >
> >
>
>
> --
> Patrick Linskey
> 202 669 5907
>