2

I want to integrate a JDBC based application into an Java EE application running in GlassFish which uses EclipseLink JPA 2.5 with MariaDB (a MySQL clone).

The JDBC based application imports data from flat files into some database tables and requires to update the next serial value for the primary keys by executing:

UPDATE dbtable SET nextid = 4711 WHERE name = 'table4Import';

using a standard JDBC connection. This statement throws an SQL timeout exception because the row is locked. It seems to be locked by EclipseLink which uses the same table for its table generator. Here is (parts of) the table containing the serial values:

CREATE TABLE dbtable (
  dbtid bigint not null primary key,
  dbtname varchar ( 50 ) not null,
  dbtnextid bigint );

This is the code for one of the JPA entities:

@Entity
@Access(AccessType.PROPERTY)
@Table( name = "table4Import" )
public class Table4ImportClass {

  private Long id = null;

  @NotNull
  @Id
  @TableGenerator( name="table4Import", allocationSize=1,
    table="dbtable", pkColumnName="dbtname",
    pkColumnValue="table4Import", valueColumnName="nextid" )
  @GeneratedValue( generator="table4Import", strategy=GenerationType.TABLE )
  public Long getId() { return this.id; }
  ...

Addendum: It is not even possible to insert a new row into that table. EclipseLink seems to lock the complete table. It is still possible to modify the table (insert & update) from another program. The lock scope seems to be the JVM in which EclipseLink is running.

Addendum 2: Put this as a bug into EclipseLink bug tracker 455756

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Jemolah
  • 1,962
  • 3
  • 24
  • 41
  • There needs to be more information as there is no way for eclipselink to obtain a JVM scoped table or row lock. Look at your JDBC app and how it is obtaining statements and locks, and turn on eclipselink logging to see what statements it is issuing – Chris Dec 21 '14 at 22:33
  • Hi Arjan. You are most probably pointing to the right direction. It seems this problem is related to the MySQL/MariaDB JDBC driver. It does not occur with PostgreSQL. Could you help me in setting up logging to see the SQL statements. The basic info from Eclipselink does not produce anything. – Jemolah Jan 07 '15 at 22:07
  • see https://wiki.eclipse.org/EclipseLink/Examples/JPA/Logging for how to set EclipseLink logging to fine or finest to see the SQL issued. – Chris Jan 08 '15 at 16:42

0 Answers0