You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Charles Moulliard <cm...@gmail.com> on 2013/10/02 14:15:40 UTC

Issue with OPENJPA_SEQUENCE_TABLE

Hi,

When using OpenJPA 2.2.0, I get an error which is really strange. OpenJPA
tries to map an entity with the table which is used to manage sequence
number (OPEN_SEQUENCE_TABLE) :

<openjpa-2.2.0-r422266:1244990 fatal general error>
org.apache.openjpa.persistence.PersistenceException: There is no row for
mapping "com.mycompany.examples.persistence.part2.model.Incident" in
sequence table "OPENJPA_SEQUENCE_TABLE", and the attempt to insert a row has
apparently failed.
	at org.apache.openjpa.jdbc.sql.DBDictionary.narrow(DBDictionary.java:4918)
	at
org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:4878)
	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.AbstractJDBCSeq.next(AbstractJDBCSeq.java:66)
	at org.apache.openjpa.util.ImplHelper.generateValue(ImplHelper.java:160)
	at
org.apache.openjpa.util.ImplHelper.generateFieldValue(ImplHelper.java:144)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignField(JDBCStoreManager.java:756)
	at org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:493)
	at org.apache.openjpa.util.ApplicationIds.assign(ApplicationIds.java:469)
	at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.assignObjectId(JDBCStoreManager.java:740)
	at
org.apache.openjpa.kernel.DelegatingStoreManager.assignObjectId(DelegatingStoreManager.java:135)
	at
org.apache.openjpa.kernel.StateManagerImpl.assignObjectId(StateManagerImpl.java:612)
	at
org.apache.openjpa.kernel.StateManagerImpl.preFlush(StateManagerImpl.java:2977)
	at org.apache.openjpa.kernel.PNewState.beforeFlush(PNewState.java:40)
	at
org.apache.openjpa.kernel.StateManagerImpl.beforeFlush(StateManagerImpl.java:1054)
	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:2112)
	at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:2072)
	at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1843)
	at
org.apache.openjpa.kernel.DelegatingBroker.flush(DelegatingBroker.java:1045)
	at
org.apache.openjpa.persistence.EntityManagerImpl.flush(EntityManagerImpl.java:663)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.7.0_40]
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)[:1.7.0_40]
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.7.0_40]
	at java.lang.reflect.Method.invoke(Method.java:606)[:1.7.0_40]
	at
org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
	at com.sun.proxy.$Proxy59.flush(Unknown Source)
	at
com.mycompany.examples.persistence.part2.dao.impl.IncidentDAOImpl.saveIncident(IncidentDAOImpl.java:71)

Caused by: java.sql.SQLException: There is no row for mapping
"com.mycompany.examples.persistence.part2.model.Incident" in sequence table
"OPENJPA_SEQUENCE_TABLE", and the attempt to insert a row has apparently
failed.
	at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq$AllocateSequenceRunnable.run(TableJDBCSeq.java:911)
	at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.allocateSequence(TableJDBCSeq.java:455)
	at
org.apache.openjpa.jdbc.kernel.TableJDBCSeq.nextInternal(TableJDBCSeq.java:300)
	at
org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq.next(AbstractJDBCSeq.java:60)
	... 285 more

The annotation used in the entity class is pretty simple :

@Entity
@Table(name = "T_INCIDENT")
public class Incident extends Abstract implements Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "INCIDENT_ID")
    private long incidentId;

What could be the problem as that was working with older version of OpenJPA
?

Regards,

Charles





--
View this message in context: http://openjpa.208410.n2.nabble.com/Issue-with-OPENJPA-SEQUENCE-TABLE-tp7585016.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Issue with OPENJPA_SEQUENCE_TABLE

Posted by Charles Moulliard <cm...@gmail.com>.
Additional info :

If I use H2 1.3.160, this config works. So something has changed in H2 DB
(1.3.173)
CREATE TABLE REPORT.T_INCIDENT (
    INCIDENT_ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT
NULL PRIMARY KEY,
    INCIDENT_REF VARCHAR(55),
    INCIDENT_DATE TIMESTAMP,
    GIVEN_NAME VARCHAR(35),
    FAMILY_NAME VARCHAR(35),
    SUMMARY VARCHAR(35),
    DETAILS VARCHAR(255),
    EMAIL VARCHAR(60),
    PHONE VARCHAR(35),
    CREATION_DATE TIMESTAMP,
    CREATION_USER VARCHAR(255)
);

& 

@Entity
@Table(name = "T_INCIDENT")
public class Incident extends Abstract implements Serializable {

    @GeneratedValue(strategy=GenerationType.SEQUENCE)
    @Column(name = "INCIDENT_ID")
    private long incidentId;





--
View this message in context: http://openjpa.208410.n2.nabble.com/Issue-with-OPENJPA-SEQUENCE-TABLE-tp7585016p7585030.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Issue with OPENJPA_SEQUENCE_TABLE

Posted by Charles Moulliard <cm...@gmail.com>.
1) Test case 1 - Without OPENJPA_SEQUENCE_TABLE

I don't have this error anymore after deleting the H2 database used for my
example : jdbc:h2:tcp://localhost/~/reportdb

and removing the OPENJPA_SEQUENCE_TABLE that I created previously

Now I see that H2 has created a :
SYSTEM_SEQUENCE_6FC4CBE2_C5C1_48C9_B049_E669E21304D2 which is well
incremented everytime a new record is created

2) Test Case 2 - OPENJPA_SEQUENCE_TABLE

If I use this Sequence Table, then I get the error reported :

CREATE TABLE REPORT.OPENJPA_SEQUENCE_TABLE (
    ID BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL
PRIMARY KEY,
    SEQUENCE_VALUE BIGINT NOT NULL
);

Unfortunately, even if I set org.apache.openjpa to DEBUG/TRACE level, I
didn't get more info in the stacktrace : 

https://gist.github.com/cmoulliard/80d65124c118db2f4737

Here is the persistence config file :

        <properties>
            <property name="openjpa.jdbc.SynchronizeMappings"
                     
value="buildSchema(SchemaAction='add,deleteTableContents')"/>
            <property name="openjpa.Log"
                      value="DefaultLevel=TRACE, Runtime=TRACE, Tool=TRACE,
SQL=TRACE"/>
            <property name="openjpa.jdbc.DBDictionary"
                      value="h2(useSchemaName=true)"/>
            <property name="openjpa.jdbc.Schema"
                      value="REPORT"/>
        </properties>


BTW, I have discovered (probably related how H2 works and when we use    
@GeneratedValue(strategy=GenerationType.AUTO)) that sometimes it uses
SEQUENCE SYSTEM and sometimes OPENJPA_SEQUENCE_TABLE





--
View this message in context: http://openjpa.208410.n2.nabble.com/Issue-with-OPENJPA-SEQUENCE-TABLE-tp7585016p7585029.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Issue with OPENJPA_SEQUENCE_TABLE

Posted by Charles Moulliard <cm...@gmail.com>.
I will make a test with more tracing. DB used is H2 (1.3.173). Previous
version was : OpenJPA 2.1



--
View this message in context: http://openjpa.208410.n2.nabble.com/Issue-with-OPENJPA-SEQUENCE-TABLE-tp7585016p7585028.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Issue with OPENJPA_SEQUENCE_TABLE

Posted by Kevin Sutter <kw...@gmail.com>.
Hi Charles,
I looked a bit at the code in the call stack...  The message is a little
misleading.  The reference to "mapping" is just a reference to the Entity
being mapped.  The code is then attempting to access the sequence defined
for this Entity's primary key in the OPENJPA_SEQUENCE_TABLE.  When it can't
find that sequence row, the code attempts to insert a new row for this
sequence.  When that operation fails, then you get the logged message:

Caused by: java.sql.SQLException: There is no row for mapping
"com.mycompany.examples.persistence.part2.model.Incident" in sequence table
"OPENJPA_SEQUENCE_TABLE", and the attempt to insert a row has apparently
failed.

So, the message should probably say, "There is no row for mapping *the
primary key for* "com.mycompany.examples.persistence.part2.model.Incident"
in sequence table
"OPENJPA_SEQUENCE_TABLE", and the attempt to insert a row has apparently
failed."

This area of the code hasn't changed in a long time.  It's been pretty
standard processing for working with the sequence table since JPA 2.0 was
implemented.  When you say that previous releases worked okay, what release
of OpenJPA are you moving from?

I would also suggest tracing.  You can turn on OpenJPA tracing.  It's not
the best, but we do log all of the SQL that we generate and issue to the
database.  That might give a clue to which database and which table is
being used for each of these operations.  Maybe the schema name is
different from what's expected, or something similar?

What database is being used?  Tracing at the database level may also be
interesting and help figure out the source.

Like I mentioned, this code path has been pretty solid.  And, the junit
buckets are run constantly against all releases of OpenJPA.  I'm not aware
of any issues in this area, but maybe there's something unique with your
environment that puts us down the wrong path.  Let us know what you find
out.

Thanks,
Kevin


On Wed, Oct 2, 2013 at 11:49 AM, Charles Moulliard <cm...@gmail.com>wrote:

> As OpenJPA is deployed on Apache Karaf (OSGI container), that will be
> difficult to create a unit test. I will try to use junit + pax exam to
> create something that we could use to reproduce the issue.
>
> BTW, this issue was not there with previous releases of OpenJPA
>
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Issue-with-OPENJPA-SEQUENCE-TABLE-tp7585016p7585024.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Re: Issue with OPENJPA_SEQUENCE_TABLE

Posted by Charles Moulliard <cm...@gmail.com>.
As OpenJPA is deployed on Apache Karaf (OSGI container), that will be
difficult to create a unit test. I will try to use junit + pax exam to
create something that we could use to reproduce the issue.

BTW, this issue was not there with previous releases of OpenJPA



--
View this message in context: http://openjpa.208410.n2.nabble.com/Issue-with-OPENJPA-SEQUENCE-TABLE-tp7585016p7585024.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Issue with OPENJPA_SEQUENCE_TABLE

Posted by Kevin Sutter <kw...@gmail.com>.
Hi Charles,
No idea why GenerationType.AUTO is not working for you on OpenJPA 2.2.0.
We have a large number of tests in our JUnit bucket that tests AUTO in a
very similar manner as your posted Entity definition.  And, these tests
work just fine.

Although the message text doesn't indicate this, the AUTO mode does require
the SEQUENCE table to exist.  If you are running with SynchronizeMappings,
then this table gets created for you automatically.  Otherwise, you have to
create it manually.  The GenerationType.SEQUENCE that eventually worked for
you doesn't require a separate table, so that might explain why that
scenario works.

Other than that, I'm not really sure.  If you can isolate the scenario to
simple junit then it might be easier to track the source of the issue.

Thanks,
Kevin


On Wed, Oct 2, 2013 at 8:10 AM, Charles Moulliard <cm...@gmail.com>wrote:

> Being able to fix my problem with the following modification
>
> @Entity
> @SequenceGenerator(name="incidentSeq", sequenceName="INCIDENT_SEQ")
> @Table(name = "T_INCIDENT")
> public class Incident extends Abstract implements Serializable {
>
>     @Id
>     @GeneratedValue(strategy=GenerationType.SEQUENCE,
> generator="incidentSeq")
>     //@GeneratedValue(strategy=GenerationType.AUTO)
>     @Column(name = "INCIDENT_ID")
>     private long incidentId;
>
> Question : Why  @GeneratedValue(strategy=GenerationType.AUTO) generates the
> error reported previously ?
>
>
>
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Issue-with-OPENJPA-SEQUENCE-TABLE-tp7585016p7585018.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Re: Issue with OPENJPA_SEQUENCE_TABLE

Posted by Charles Moulliard <cm...@gmail.com>.
Being able to fix my problem with the following modification

@Entity
@SequenceGenerator(name="incidentSeq", sequenceName="INCIDENT_SEQ")
@Table(name = "T_INCIDENT")
public class Incident extends Abstract implements Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE,
generator="incidentSeq")
    //@GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name = "INCIDENT_ID")
    private long incidentId;

Question : Why  @GeneratedValue(strategy=GenerationType.AUTO) generates the
error reported previously ?



--
View this message in context: http://openjpa.208410.n2.nabble.com/Issue-with-OPENJPA-SEQUENCE-TABLE-tp7585016p7585018.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.