Java Persistence API and TableGenerator

hi everybody....

i'm developing a web project with java persistence api.( no EJB's ).

my entity classes have primary keys that are generated automatically with @TableGenerator and @generatedValue annotations..

there are some situtations, where i want to get manually the next id for the class and set it with a call to setID( ..).

is there a way i can do this?

thanx...

[409 byte] By [nmiga] at [2007-11-27 4:20:56]
# 1

@Id

@GeneratedValue( @GeneratedValue(strategy= GenerationType.TABLE, generator="SOMENAME")

public int setId() {

returrn this.id;

}

in the database you need to create table using following commands

CREATE TABLE SEQUENCE

(

SEQ_NAME VARCHAR(50),

SEQ_COUNT DECIMAL(15)

);

and insert a row initally with the same "SOMENAME" like

insert into sequence values ( "SOMENAME", 1);

you can get the next id by adding 50(default) to "SELECT SEQ_COUNT FROM SEQUENCE WHERE SEQ_NAME = "SOMENAME"

hope this provides a solution.

amarpolimeraa at 2007-7-12 9:28:03 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...