Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Table Sequence
Table Sequence [message #379884] Fri, 22 August 2008 07:55 Go to next message
Rama Notowidigdo is currently offline Rama NotowidigdoFriend
Messages: 19
Registered: July 2009
Junior Member
I'm using Table Sequence to assign the primary key.

Is there a way to assign sequence ahead of time when using JPA?

in Eclipselink, you can do uow.assignSequence().
Is there any good way to do this in JPA?

Thanks.

Cheers,
rgn
Re: Table Sequence [message #380513 is a reply to message #379884] Tue, 26 August 2008 18:06 Go to previous messageGo to next message
Gordon Yorke is currently offline Gordon YorkeFriend
Messages: 78
Registered: July 2009
Member
That depends on what you mean by ahead of time. On the call to
EntityManager.persist() the sequence value will be assigned to the ID of
the persisted object. This is before any changes are flushed to the
database.
--Gordon
Re: Table Sequence [message #380520 is a reply to message #380513] Wed, 27 August 2008 01:25 Go to previous messageGo to next message
Rama Notowidigdo is currently offline Rama NotowidigdoFriend
Messages: 19
Registered: July 2009
Junior Member
Thanks for the response Gordon.
That's exactly what I've been relying but I'm looking something earlier.
Because if not mistaken persist() would finish validation of objects in
transaction already.

I'm looking to do such as:

Person aPerson = new Person();
uow.assignSequenceNumber(aPerson);


And if I were to use persist() for every new object to get id assign
ahead of time, what would there be a performance impact?
Re: Table Sequence [message #380529 is a reply to message #380520] Wed, 27 August 2008 13:31 Go to previous messageGo to next message
James is currently offline JamesFriend
Messages: 272
Registered: July 2009
Senior Member
Using persist should be ok, are you having any specific issue? There
should be little to no performance cost in using persist to assign the id,
you have to persist the objects at some point anyway.

If you really don't want to use persist for some reason, you could always
cast your EntityManager to the EclipseLink interface and obtain the
UnitOfWork.

-- James
Re: Table Sequence [message #380545 is a reply to message #380529] Fri, 29 August 2008 01:41 Go to previous messageGo to next message
Rama Notowidigdo is currently offline Rama NotowidigdoFriend
Messages: 19
Registered: July 2009
Junior Member
Thanks, nothing specific.
I'm assuming that persist() does a lot of pre-commit activities such as
registered object comparison to find out what fields needs to be updated
etc. From what I senses that is not the case?
Re: Table Sequence [message #381065 is a reply to message #380545] Sat, 30 August 2008 19:18 Go to previous messageGo to next message
Rama Notowidigdo is currently offline Rama NotowidigdoFriend
Messages: 19
Registered: July 2009
Junior Member
James,

How do we do the casting to obtain Uow?

Session aSession = (Session) anEntitiyManager;
aSession.acquireUnitOfWork();

Is this right?

Thanks.

Cheers,
rgn
Re: Table Sequence [message #381070 is a reply to message #381065] Tue, 02 September 2008 13:48 Go to previous message
James is currently offline JamesFriend
Messages: 272
Registered: July 2009
Senior Member
You can cast to the EclipseLink JpaEntityManager
(org.eclipse.persistence.jpa).

((JpaEntityManager) entityManager).getActiveSession()

Or,

JpaHelper.getEntityManager(entityManager).getActiveSession()

-- James
Previous Topic:TIMESTAMP calculations
Next Topic:Roadmap for EclipseLink 1.1
Goto Forum:
  


Current Time: Thu Apr 25 01:43:02 GMT 2024

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

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

Back to the top