While attempting to fix code given to me by my customer, I created a simple test project that has three tables, I had my program create the tables (JPA 2.1 in NetBeans 7.3.1) in my persistence.xml file.
I have one table (ActivityLog) with an Id of type Long which has been annotated with "@GeneratedValue(strategy = GenerationType.AUTO)".
So, if I type:
EntityManager em = ...
em.getTransaction().begin();
ActivityLog l = new ActivityLog();
l.setTimeStamp(new Date());
em.persist(l); <----------------- fails here
What am I missing? Here is the exception:
Exception [EclipseLink-4011] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Exception Description: Error preallocating sequence numbers. The sequence table information is not complete.
at org.eclipse.persistence.exceptions.DatabaseException.errorPreallocatingSequenceNumbers(DatabaseException.java:150)
at org.eclipse.persistence.sequencing.StandardSequence.getGeneratedVector(StandardSequence.java:73)
at org.eclipse.persistence.sequencing.DefaultSequence.getGeneratedVector(DefaultSequence.java:163)
at org.eclipse.persistence.sequencing.Sequence.getGeneratedVector(Sequence.java:257)
at org.eclipse.persistence.internal.sequencing.SequencingManager$Preallocation_Transaction_NoAccessor_State.getNextValue(SequencingManager.java:468)
at org.eclipse.persistence.internal.sequencing.SequencingManager.getNextValue(SequencingManager.java:1067)
at org.eclipse.persistence.internal.sequencing.ClientSessionSequencing.getNextValue(ClientSessionSequencing.java:70)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.assignSequenceNumber(ObjectBuilder.java:359)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.assignSequenceNumber(ObjectBuilder.java:318)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.assignSequenceNumber(UnitOfWorkImpl.java:484)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNotRegisteredNewObjectForPersist(UnitOfWorkImpl.java:4284)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.registerNotRegisteredNewObjectForPersist(RepeatableWriteUnitOfWork.java:518)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4229)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:496)
|
Please enable automatic schema generation or create table for storing ID manually when using Table, Sequence or IDENTITY ID Generation.
opt#1. Enable automatic schema generation
org.eclipse.persistence.jpa.PersistenceProvider
...
...
opt#2. Create table for storing ID manually
Define Sequence in your entity
@SequenceGenerator(name="Emp_Gen", sequenceName="Emp_Seq")
@Id @GeneratedValue(generator="Emp_Gen")
private int getId;
SQL script to create sequence
CREATE SEQUENCE Emp_Seq
MINVALUE 1
START WITH 1
INCREMENT BY 1
|
Option 1 does not work. I have
set in my persistence.xml file.
I still get the same exception. Trying option 2.
|
I can now inform you that Option 2 did not work either. Same exception.
|
Oops, my XML entry for Option 1 did not show up in my previous message. The actual element looks like this in my persistence.xml file:
property name="eclipselink.ddl-generation" value="drop-and-create-tables"
|
Checked. Sorry. The pasted solution is wrong.
In fact, you need to download HXTT Glassfish Support Package, and add
lt;property name="eclipselink.platform.class.name" value="com.hxtt.support.eclipselink.DbfPlatform" / gt;
in your persistence.xml , then your issue will disappear.
|
For the latest persistence.xml version, you can use eclipselink.target-database property to replace eclipselink.platform.class.name .
Passed test for the following parameters with the latest package:
@GeneratedValue(strategy = GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GeneratedValue(strategy = GenerationType.TABLE)
|