How can TopLink use sequencing to assign the generated primary key value to the object at creation time?
TopLink supports sequencing by assigning the object a unique identifier when it is inserted into the database. TopLink assigns the identifier here because this is the first time TopLink gets access to the object. When using native sequencing on Sybase, SQL Server and Informix the identifier cannot be obtained until after the insert. If you want the sequence number assigned at creation time instead of during the insert: Create your new object and assign it its identifier by using the following protocol. You must provide the sequence name. Number nextID = session.getPlatform().getSequenceNumberNamed(” SEQ_NAME”, session, “SESSION_NAME”); Note that this is not a public API protocol, although it is publicly accessible. Write the object normally through TopLink. Within a unit of work all registered new objects can also be assigned sequence numbers through the assignSequenceNumber(Object) and assignSequenceNumbers() methods.
Related Questions
- Under what circumstances will DB2® Database allow an SQL statement to update more than one primary key value at a time?
- How can TopLink use sequencing to assign the generated primary key value to the object at creation time?
- When can an insert of a new primary key value threaten referential integrity?