users@glassfish.java.net

Retrieve values from ID Generator (TableGenerator ) in Java

From: <glassfish_at_javadesktop.org>
Date: Thu, 22 Nov 2007 07:36:03 PST

Hello,

I have the following problem:

For a composite primary key (id + version), I would need auto-generated values for the Id in some cases (e.g. for the initial creation).

More precise, I would like to do the following:
1.) define a table generator in my class

[i]@TableGenerator(
    name="elemendIdGen",
    table="INT_ID_GEN",
    pkColumnName="GEN_KEY",
    valueColumnName="GEN_VALUE",
    pkColumnValue="ELEMENT_ID",
    allocationSize=1
)[/i]

2.) access/initiate the value generation from Java (i.e. in a factory)

[i]element.setId(idGeneratorFactory.getGenerator("elementIdGen").getNextValue());[/i]

Is there some possibilty to do this? I looked into the persistence and toplink documenation and could not find anything. A small coding example would be very welcome.

Thanks in Advance.
[Message sent by forum member 'tipunch' (tipunch)]

http://forums.java.net/jive/thread.jspa?messageID=246817