JPA: Pre-allocate ID block not work fine - jpa

I'm trying to manage the ID generation through the annotation #TableGenerator with allocationSize default. As I understand it, to avoid updating the row for every single identifier that gets requested, an allocation size is used. In theory, the provider should pre-allocate a block of identifiers equal to the value of allocationSize - 50 in this case - and then give out identifiers from memory as requested until the block is used up or the transaction comes to an end.
I Use Eclipselink (EL) with JBoss 7.1.
The problem is that this does not happen. Inserting 3 records in the table Students, EL pre allocates for each record a block of 50 ID, even if the transaction is the same. Then, for each record, there is always access to the table. From the logs I see 3 pre allocations and three pairs of select/update query for the ID and the IDs are generated 1- 51 -101 and the sequence has as its final value 150. Piece of log
Connection acquired from connection pool
UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
bind => [50, TABLE_SEQ]
SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?
bind => [TABLE_SEQ]
local sequencing preallocation for TABLE_SEQ: objects: 50 , first: 1, last: 50
Connection released to connection pool [default].
Connection acquired from connection pool
UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
bind => [50, TABLE_SEQ]
SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?
bind => [TABLE_SEQ]
local sequencing preallocation for TABLE_SEQ: objects: 50 , first: 51, last: 100
Connection released to connection pool [default].
Being a single transaction, I expected sequential IDs (1-2-3) and the final value of the sequence 50.
Where am I wrong? I tried to do research on the forum but I can not even solve the problem.
Below is the simple test code.
Thanks for the help.
Entity Student
#Entity
#Table(name="STUDENTS")
public class Student implements Serializable
{
private static final long serialVersionUID = 4771385985502937621L;
#TableGenerator(name="TABLE_SEQ")
#Id #Column(name="ID_STUDENT") #GeneratedValue(generator="TABLE_SEQ")
private int idStudent;
private String name;
public int getIdStudent() {
return idStudent;
}
public void setIdStudent(int idStudent) {
this.idStudent = idStudent;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name= name;
}
}
EJB
#Stateless(name="EJBStudent")
public class EJBStudent implements EJBStudentRemote
{
#PersistenceContext(unitName="JPA_Test")
private EntityManager manager;
public EJBStudent() {
}
#Override
public void insertStudents()
{
manager.getTransaction().begin();
Student student1 = new Student();
student1.setName("Anna");
manager.persist(student1);
Student student2 = new Student();
student2.setName("Paolo");
manager.persist(student2);
Student student3 = new Student();
student3.setName("Luigi");
manager.persist(student3);
manager.flush();
}
}
EDIT
#Chris thanks for response.
This is the finest log. I only noticed a major difference. For each insert, it create a different connection. However, if run the query suggested by #wypieprz first of all persist, the connection is always the same.
Invoking org.jboss.invocation.InterceptorContext$Invocation.insertStudent
[EL Finer]: connection: 2014-04-26 18:05:14.228--ServerSession(320769650)--Thread(Thread[EJB default - 1,5,EJB default])--client acquired: 1096067977
[EL Finer]: transaction: 2014-04-26 18:05:14.236--ClientSession(1096067977)--Thread(Thread[EJB default - 1,5,EJB default])--acquire unit of work: 698749338
[EL Finest]: transaction: 2014-04-26 18:05:14.237--UnitOfWork(698749338)--Thread(Thread[EJB default - 1,5,EJB default])--persist() operation called on: jpa.test.model.Student#55cdaad2.
[EL Finest]: connection: 2014-04-26 18:05:14.238--ServerSession(320769650)--Connection(118375432)--Thread(Thread[EJB default - 1,5,EJB default])--Connection acquired from connection pool [default].
[EL Finest]: query: 2014-04-26 18:05:14.24--ClientSession(1096067977)--Thread(Thread[EJB default - 1,5,EJB default])--Execute query DataModifyQuery(name="TABLE_SEQ" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + #PREALLOC_SIZE WHERE SEQ_NAME = #SEQ_NAME")
[EL Finest]: connection: 2014-04-26 18:05:14.242--ClientSession(1096067977)--Thread(Thread[EJB default - 1,5,EJB default])--reconnecting to external connection pool
[EL Fine]: sql: 2014-04-26 18:05:14.249--ClientSession(1096067977)--Connection(1243300871)--Thread(Thread[EJB default - 1,5,EJB default])--UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
bind => [50, TABLE_SEQ]
[EL Finest]: query: 2014-04-26 18:05:14.252--ClientSession(1096067977)--Thread(Thread[EJB default - 1,5,EJB default])--Execute query ValueReadQuery(name="TABLE_SEQ" sql="SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = #SEQ_NAME")
[EL Fine]: sql: 2014-04-26 18:05:14.253--ClientSession(1096067977)--Connection(1243300871)--Thread(Thread[EJB default - 1,5,EJB default])--SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?
bind => [TABLE_SEQ]
[EL Finest]: sequencing: 2014-04-26 18:05:14.256--ClientSession(1096067977)--Connection(1243300871)--Thread(Thread[EJB default - 1,5,EJB default])--local sequencing preallocation for TABLE_SEQ: objects: 50 , first: 1, last: 50
[EL Finest]: connection: 2014-04-26 18:05:14.258--ServerSession(320769650)--Connection(118375432)--Thread(Thread[EJB default - 1,5,EJB default])--Connection released to connection pool [default].
[EL Finest]: sequencing: 2014-04-26 18:05:14.259--UnitOfWork(698749338)--Thread(Thread[EJB default - 1,5,EJB default])--assign sequence to the object (1 -> jpa.test.model.Student#55cdaad2)
[org.hibernate.validator.util.Version] (EJB default - 1) Hibernate Validator 4.2.0.Final
[EL Finest]: transaction: 2014-04-26 18:05:14.325--UnitOfWork(698749338)--Thread(Thread[EJB default - 1,5,EJB default])--persist() operation called on: jpa.test.model.Student#59887d29.
[EL Finest]: connection: 2014-04-26 18:05:14.326--ServerSession(320769650)--Connection(265370795)--Thread(Thread[EJB default - 1,5,EJB default])--Connection acquired from connection pool [default].
[EL Finest]: query: 2014-04-26 18:05:14.327--ClientSession(1096067977)--Thread(Thread[EJB default - 1,5,EJB default])--Execute query DataModifyQuery(name="TABLE_SEQ" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?")
[EL Finest]: connection: 2014-04-26 18:05:14.328--ClientSession(1096067977)--Thread(Thread[EJB default - 1,5,EJB default])--reconnecting to external connection pool
[EL Fine]: sql: 2014-04-26 18:05:14.329--ClientSession(1096067977)--Connection(1910900393)--Thread(Thread[EJB default - 1,5,EJB default])--UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
bind => [50, TABLE_SEQ]
[EL Finest]: query: 2014-04-26 18:05:14.331--ClientSession(1096067977)--Thread(Thread[EJB default - 1,5,EJB default])--Execute query ValueReadQuery(name="TABLE_SEQ" sql="SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?")
[EL Fine]: sql: 2014-04-26 18:05:14.332--ClientSession(1096067977)--Connection(1910900393)--Thread(Thread[EJB default - 1,5,EJB default])--SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?
bind => [TABLE_SEQ]
[EL Finest]: sequencing: 2014-04-26 18:05:14.334--ClientSession(1096067977)--Connection(1910900393)--Thread(Thread[EJB default - 1,5,EJB default])--local sequencing preallocation for TABLE_SEQ: objects: 50 , first: 51, last: 100
[EL Finest]: connection: 2014-04-26 18:05:14.335--ServerSession(320769650)--Connection(265370795)--Thread(Thread[EJB default - 1,5,EJB default])--Connection released to connection pool [default].
[EL Finest]: sequencing: 2014-04-26 18:05:14.336--UnitOfWork(698749338)--Thread(Thread[EJB default - 1,5,EJB default])--assign sequence to the object (51 -> jpa.test.model.Student#59887d29)
[EL Finest]: transaction: 2014-04-26 18:05:14.337--UnitOfWork(698749338)--Thread(Thread[EJB default - 1,5,EJB default])--persist() operation called on: jpa.test.model.Student#20f5e794.
[EL Finest]: connection: 2014-04-26 18:05:14.338--ServerSession(320769650)--Connection(1882633843)--Thread(Thread[EJB default - 1,5,EJB default])--Connection acquired from connection pool [default].
[EL Finest]: query: 2014-04-26 18:05:14.338--ClientSession(1096067977)--Thread(Thread[EJB default - 1,5,EJB default])--Execute query DataModifyQuery(name="TABLE_SEQ" sql="UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?")
[EL Finest]: connection: 2014-04-26 18:05:14.339--ClientSession(1096067977)--Thread(Thread[EJB default - 1,5,EJB default])--reconnecting to external connection pool
[EL Fine]: sql: 2014-04-26 18:05:14.34--ClientSession(1096067977)--Connection(402944403)--Thread(Thread[EJB default - 1,5,EJB default])--UPDATE SEQUENCE SET SEQ_COUNT = SEQ_COUNT + ? WHERE SEQ_NAME = ?
bind => [50, TABLE_SEQ]
[EL Finest]: query: 2014-04-26 18:05:14.342--ClientSession(1096067977)--Thread(Thread[EJB default - 1,5,EJB default])--Execute query ValueReadQuery(name="TABLE_SEQ" sql="SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?")
[EL Fine]: sql: 2014-04-26 18:05:14.343--ClientSession(1096067977)--Connection(402944403)--Thread(Thread[EJB default - 1,5,EJB default])--SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = ?
bind => [TABLE_SEQ]
[EL Finest]: sequencing: 2014-04-26 18:05:14.345--ClientSession(1096067977)--Connection(402944403)--Thread(Thread[EJB default - 1,5,EJB default])--local sequencing preallocation for TABLE_SEQ: objects: 50 , first: 101, last: 150
[EL Finest]: connection: 2014-04-26 18:05:14.346--ServerSession(320769650)--Connection(1882633843)--Thread(Thread[EJB default - 1,5,EJB default])--Connection released to connection pool [default].
[EL Finest]: sequencing: 2014-04-26 18:05:14.347--UnitOfWork(698749338)--Thread(Thread[EJB default - 1,5,EJB default])--assign sequence to the object (101 -> jpa.test.model.Student#20f5e794)
[EL Finer]: transaction: 2014-04-26 18:05:14.348--UnitOfWork(698749338)--Thread(Thread[EJB default - 1,5,EJB default])--begin unit of work flush
[EL Finest]: query: 2014-04-26 18:05:14.351--UnitOfWork(698749338)--Thread(Thread[EJB default - 1,5,EJB default])--Execute query InsertObjectQuery(jpa.test.model.Student#59887d29)
[EL Finest]: connection: 2014-04-26 18:05:14.353--ServerSession(320769650)--Connection(1582457600)--Thread(Thread[EJB default - 1,5,EJB default])--Connection acquired from connection pool [default].
[EL Finest]: connection: 2014-04-26 18:05:14.354--ClientSession(1096067977)--Thread(Thread[EJB default - 1,5,EJB default])--reconnecting to external connection pool
[EL Fine]: sql: 2014-04-26 18:05:14.354--ClientSession(1096067977)--Connection(1927398752)--Thread(Thread[EJB default - 1,5,EJB default])--INSERT INTO STUDENTS (ID_STUDENT, NAME) VALUES (?, ?)
bind => [51, Paolo]
[EL Finest]: query: 2014-04-26 18:05:14.37--UnitOfWork(698749338)--Thread(Thread[EJB default - 1,5,EJB default])--Execute query InsertObjectQuery(jpa.test.model.Student#55cdaad2)
[EL Fine]: sql: 2014-04-26 18:05:14.371--ClientSession(1096067977)--Connection(1927398752)--Thread(Thread[EJB default - 1,5,EJB default])--INSERT INTO STUDENTS (ID_STUDENT, NAME) VALUES (?, ?)
bind => [1, Anna]
[EL Finest]: query: 2014-04-26 18:05:14.373--UnitOfWork(698749338)--Thread(Thread[EJB default - 1,5,EJB default])--Execute query InsertObjectQuery(jpa.test.model.Student#20f5e794)
[EL Fine]: sql: 2014-04-26 18:05:14.373--ClientSession(1096067977)--Connection(1927398752)--Thread(Thread[EJB default - 1,5,EJB default])--INSERT INTO STUDENTS (ID_STUDENT, NAME) VALUES (?, ?)
bind => [101, Luigi]
[EL Finer]: transaction: 2014-04-26 18:05:14.375--UnitOfWork(698749338)--Thread(Thread[EJB default - 1,5,EJB default])--end unit of work flush
[EL Finer]: transaction: 2014-04-26 18:05:14.376--UnitOfWork(698749338)--Thread(Thread[EJB default - 1,5,EJB default])--resume unit of work
Exiting org.jboss.invocation.InterceptorContext$Invocation.insertStudent
Business method insertStudent in org.jboss.invocation.InterceptorContext$Invocation takes 5878 ms to execute
18:05:14,409 INFO [org.jboss.as.naming] (Remoting "pc" task-1) JBAS011806: Channel end notification received, closing channel Channel ID 03cefe33 (inbound) of Remoting connection 3138554d to /127.0.0.1:65303

Problem solved.
In order to work well with EclipseLink transactions, is must specify (in the persistence.xml file) which server we are using, in my case:
<property name="eclipselink.target-server" value="JBoss"/>

Related

JPA jsonb query issue with positional argument

I'm having an issue with JPA and json querying. My JPA is Eclipselink and I use Postgres DB.
My query is
with values as(select id, inputspecifications as spec from process where commercial = True and inputspecifications #> '[{\"type\":\"raster\"}]') select id from values where (spec -> 'platforms' is null or (spec -> 'platforms' -> 'satellites' is not null and (spec -> 'platforms' -> 'satellites' ?& array['310802']))
The query works fine until the array inclusion comparison (last bit). It seems JPA is seeing ?& as a positional argument, as per the fine logs
[EL Warning]: sql: 2022-11-07 10:22:05.336--ServerSession(65586123)--Missing Query parameter for named argument: & "null" will be substituted.
[EL Fine]: sql: 2022-11-07 10:22:05.336--ServerSession(65586123)--Connection(1463355115)--with values as(select id, inputspecifications as spec from process where commercial = True and inputspecifications #> '[{"type":"raster"}]') select id from values where (spec -> 'platforms' is null or (spec -> 'platforms' -> 'satellites' is not null and (spec -> 'platforms' -> 'satellites' ? array['310802']))
bind => [null]
[EL Fine]: sql: 2022-11-07 10:22:05.343--ServerSession(65586123)--SELECT 1
[EL Warning]: 2022-11-07 10:22:05.344--UnitOfWork(446445803)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.7.6.v20200131-b7c997804f): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: syntax error at or near "$1"
Position: 293
Error Code: 0
I have tried escaping in various ways, ie \?&, \?\&,... all fail one way or another...
Any idea how to make jpa NOT see ?& as a positional parameter?

Does cascade happen in 1 transaction?

I save the Product which cascade persist the productMaterial. However, when the productMaterial throws DataIntegrityViolationException the product is rollbacked, which seems like cascade is done in 1 transaction, but i don't find any docs saying that it does. Can someone clarify it for me?
NOTE: I DO NOT use #Transactional
Material material = new Material();
material.setId(1);
Product newProduct = new Product();
ProductMaterial productMaterial = new ProductMaterial();
newProduct.setName("bàn chải");
newProduct.setPrice(1000);
newProduct.setCreatedAt(new Date());
newProduct.setProductMaterials(Collections.singletonList(productMaterial));
productMaterial.setProduct(newProduct);
productMaterial.setMaterial(material);
productRepository.save(newProduct);
Here is the hibernate execution:
Hibernate:
/* insert com.vietnam.hanghandmade.entities.Product
*/ insert
into
product
(created_at, name, price, id)
values
(?, ?, ?, ?)
2020-11-10 14:55:38.281 TRACE 65729 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [TIMESTAMP] - [Tue Nov 10 14:55:38 JST 2020]
2020-11-10 14:55:38.281 TRACE 65729 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [VARCHAR] - [bàn chải]
2020-11-10 14:55:38.281 TRACE 65729 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [INTEGER] - [1000]
2020-11-10 14:55:38.281 TRACE 65729 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [OTHER] - [e5729490-a0f8-48e7-9600-eeeba8b8f279]
Hibernate:
/* insert com.vietnam.hanghandmade.entities.ProductMaterial
*/ insert
into
product_material
(material_id, product_id)
values
(?, ?)
2020-11-10 14:55:38.324 TRACE 65729 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [INTEGER] - [1]
2020-11-10 14:55:38.324 TRACE 65729 --- [nio-8080-exec-2] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [OTHER] - [e5729490-a0f8-48e7-9600-eeeba8b8f279]
2020-11-10 14:55:38.328 WARN 65729 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 23503
2020-11-10 14:55:38.328 ERROR 65729 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: insert or update on table "product_material" violates foreign key constraint "product_material_material_id_fkey"
Detail: Key (material_id)=(1) is not present in table "material".
NOTE: This answer missed the point of the question, which is about “cascading persist” – it talks about “cascading delete” for foreign keys.
The cascading delete or update is part of the action of the system trigger that implements foreign key constraints, and as such it runs in the same transaction as the triggering statement.
I cannot find a place in the fine manual that spells this out, but it is obvious if you think about it: if the cascading delete were run in a separate transaction, it would be possible that the delete succeeds and the cascading delete fails, which would render the database inconsistent and is consequently not an option.

Using BigDecimal field in #Query and populating it with #Param field is throwing Sql Error

This following is the query i am using for setting BigDecimal value in Query but failing as error in SQL Syntax
#Query(value="Select f.id,s.student_id,f.feesPaid,f.fees_pending,f.paid_datetime from Fees f inner join Student s where f.feesPaid > :amt")
List<Fees> findFirst3ByFeesPaidGreaterThan( #Param(value = "amt") BigDecimal amt);
the following is the error
Hibernate: select fees0_.id as col_0_0_, student1_.student_id as col_1_0_, fees0_.fees_paid as col_2_0_, fees0_.fees_pending as col_3_0_, fees0_.paid_datetime as col_4_0_ from fees fees0_ inner join student student1_ on where fees0_.fees_paid>?
2019-05-07 20:06:16.779 WARN 21752 --- [nio-8082-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1064, SQLState: 42000
2019-05-07 20:06:16.779 ERROR 21752 --- [nio-8082-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where fees0_.fees_paid>500' at line 1
I am able to use the query method name but i wanted to do it using Query as mentioned above.

OPEN JPA - #TableGenerator with negative values running in infinate loop

#TableGenerator(name = "ParticipantGen", schema = "sa", table = "ADP_TBL_OID", pkColumnName = "TYPE_ID", pkColumnValue = "5321", valueColumnName = "OBJ_NUM", allocationSize = 50)
#Id
#GeneratedValue(strategy = GenerationType.TABLE, generator = "ParticipantGen")
private BigInteger objid;
I have a configuration like above to generate the primary key for a table.
The next value for the key is a negative number.
When I run the flow, Somehow the JPA is not accepting -ve numbers and running in infinite loop to get a positive number.
Because of this the application is blocking since the db thread to insert table record is not released.
Would be great if somebody can help here.
Log:
302378 openjpa TRACE [[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t -1257420086, conn 73905> [0 ms] spent
302378 openjpa TRACE [[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t -1257420086, conn 73905> executing prepstmnt 277699 UPDATE SA.ADP_TBL_OID SET OBJ_NUM = ? WHERE TYPE_ID = ? AND OBJ_NUM = ? [params=(long) -2116596711, (String) 5321, (long) -2116596761]
302378 openjpa TRACE [[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t -1257420086, conn 73905> [0 ms] spent
302379 openjpa TRACE [[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t -1257420086, conn 73905> executing prepstmnt 277700 SELECT OBJ_NUM FROM SA.ADP_TBL_OID WHERE TYPE_ID = ? FOR UPDATE [params=(String) 5321]
302379 openjpa TRACE [[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t -1257420086, conn 73905> [0 ms] spent
302379 openjpa TRACE [[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t -1257420086, conn 73905> executing prepstmnt 277702 UPDATE SA.ADP_TBL_OID SET OBJ_NUM = ? WHERE TYPE_ID = ? AND OBJ_NUM = ? [params=(long) -2116596661, (String) 5321, (long) -2116596711]
302380 openjpa TRACE [[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t -1257420086, conn 73905> [1 ms] spent
302380 openjpa TRACE [[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t -1257420086, conn 73905> executing prepstmnt 277703 SELECT OBJ_NUM FROM SA.ADP_TBL_OID WHERE TYPE_ID = ? FOR UPDATE [params=(String) 5321]
302381 openjpa TRACE [[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t -1257420086, conn 73905> [1 ms] spent
302381 openjpa TRACE [[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t -1257420086, conn 73905> executing prepstmnt 277705 UPDATE SA.ADP_TBL_OID SET OBJ_NUM = ? WHERE TYPE_ID = ? AND OBJ_NUM = ? [params=(long) -2116596611, (String) 5321, (long) -2116596661]
302381 openjpa TRACE [[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t -1257420086, conn 73905> [0 ms] spent
302381 openjpa TRACE [[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t -1257420086, conn 73905> executing prepstmnt 277706 SELECT OBJ_NUM FROM SA.ADP_TBL_OID WHERE TYPE_ID = ? FOR UPDATE [params=(String) 5321]
302382 openjpa TRACE [[ACTIVE] ExecuteThread: '4' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t -1257420086, conn 73905> [1 ms] spent

JPA / EclipseLink - create script source with one SQL statement taking multiple lines

I want to let the persistence provider (EclipseLink 2.5.0) automatically create the tables in the, already existing, database by using the persistence unit property "javax.persistence.schema-generation.create-script-source" and a valid SQL-DDL-script.
persistence.xml:
<property name="javax.persistence.schema-generation.create-script-source" value="data/ddl.sql"/>
ddl.sql:
USE myDatabase;
CREATE TABLE MyTable (
id INTEGER NOT NULL AUTO_INCREMENT,
myColumn VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8 DEFAULT COLLATE = utf8_bin;
But I got the following error:
[EL Warning]: 2014-02-12 13:31:44.778--ServerSession(768298666)--Thread(Thread[main,5,main])--Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Error Code: 1064
Call: CREATE TABLE MyTable (
Query: DataModifyQuery(sql="CREATE TABLE MyTable (")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:331)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:895)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:957)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:630)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:558)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1995)
at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:570)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:242)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:228)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeNoSelectCall(DatasourceCallQueryMechanism.java:271)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeNoSelect(DatasourceCallQueryMechanism.java:251)
at org.eclipse.persistence.queries.DataModifyQuery.executeDatabaseQuery(DataModifyQuery.java:85)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:899)
at org.eclipse.persistence.internal.sessions.AbstractSession.internalExecuteQuery(AbstractSession.java:3207)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1797)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1779)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1730)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeNonSelectingCall(AbstractSession.java:1499)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeNonSelectingSQL(AbstractSession.java:1517)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.writeSourceScriptToDatabase(EntityManagerSetupImpl.java:4065)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.writeDDL(EntityManagerSetupImpl.java:3910)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.writeDDL(EntityManagerSetupImpl.java:3783)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:724)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getDatabaseSession(EntityManagerFactoryDelegate.java:182)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getDatabaseSession(EntityManagerFactoryImpl.java:527)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactoryImpl(PersistenceProvider.java:140)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:177)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at nl.tent.competent.data.access.Main.main(Main.java:22)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2815)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:885)
... 29 more
It seems that the carriage return line feed (newline) is the problem. And if I change the SQL-DDL-script, so that one SQL-statement only takes one line, everything is working fine.
adjusted ddl.sql:
USE myDatabase;
CREATE TABLE MyTable (id INTEGER NOT NULL AUTO_INCREMENT, myColumn VARCHAR(255) NOT NULL, PRIMARY KEY (id) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8 DEFAULT COLLATE = utf8_bin;
But I don't want to reformat my SQL-DDL-script for readability. Please help!
If someone still faces this problem, it can be solved by adding following parameter (found here):
<property name="hibernate.hbm2ddl.import_files_sql_extractor" value="org.hibernate.tool.hbm2ddl.MultipleLinesSqlCommandExtractor" />