views:

30

answers:

1

I am using JPA 2 for an enterprise application, and my DBA's just hit me with a twist.

They want me to use the group's centralized object ID generator for all my tables. This means rather than using table values or a sequence table, I will need to call a web service to get a batch of ~50 ids.

Then, as I persist any new object, I would need to inject this id first, and save that to the table.

So how would I manipulate the @Id column of an entity to handle this.

Is it as simple as setting a key before I persist? I suspect that would throw some sort of unmanaged entity with ID set error.

A: 

Figured it out. Amazingly complex ;) - just remove the GeneratedValue annotation from the key field.

It is intended for Native Ids like SSN or email, but works regardless of source.

@Entity
public class Client{

    @Id
    @Column(name="CLNT_ID") 
    private long key;
    @Column(name="CLNT_NUM")
    private String clientNumber;
...
}
Eddie