Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » TableGenerator Sequencing options(changing the way jpa does sequencing from tables)
TableGenerator Sequencing options [message #644221] Fri, 10 December 2010 02:06 Go to next message
Dave Brosius is currently offline Dave BrosiusFriend
Messages: 34
Registered: July 2009
Member
Greetings,

We have a collection of legacy applications all around a common schema, running on a common database instance. For primary keys we use the the table based next key pattern, using a legacy (read adhoc) implementation of that algorithm.

We are introducing a new product into this environment, same schema, save database instance. However since it's new, we are using JPA and EclipseLink to do our database management.

We have specified the TableGenerator annotation using the same table and field names and values as is used with the legacy products.

However we've stumbled upon a mismatch that is a problem.

In our legacy system, the value of the key in the table is the value of the 'next key'. That is, the legacy products retrieve the value in the table, use that for a primary key, and then increment the value in the table.

JPA(EclipseLink) on the other hand, increments the value in the table, and uses the incremented value as the primary key.

Thus if the new product using JPA gets a new primary key, and then the legacy system gets a primary key, there will be key collision.

As we'd rather not fuss with a suite of venerable products, we were hoping to solve this with JPA.

Is there a way to instruct JPA to switch how it uses keys in a TableGenerator, ie we'd like it to use the value it finds in the table for the next key, and then increment that key for the next use?



Re: TableGenerator Sequencing options [message #644358 is a reply to message #644221] Fri, 10 December 2010 16:56 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Hello,

JPA doesn't provide a way to change this, but you can by using a customizer to call native api through QuerySequence's setShouldSkipUpdate(true) on the sequence objects. I have not tested this, but it should just be a matter of itterating over the collection returned from
session.getLogin().getSequences()
in a customizer, casting and calling setShouldSkipUpdate(true).

Best Regards,
Chris
Previous Topic:JPA 2 Query casting throwing exception
Next Topic:JPA/Eclipselink poor performance batch update entity on ManyToOne relationship changes
Goto Forum:
  


Current Time: Fri Apr 26 17:20:52 GMT 2024

Powered by FUDForum. Page generated in 0.03295 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top