C,
JPA provides similar, but not exact capabilities through table generators.
The main difference in JPA is that a table generator can be used to generate
IDs for multiple entities from a single table while the approach you've
provided appears to be capable of only managing a single ID per table.
JPA table generators are able to manage multiple id's by having a sequence
name and sequence value column in the table. A TableGenerator keys off the
value defined by "pkColumnValue" (default is "DEFAULT" if not specified) in
column "pkColumnName" to generate a new block of keys.
Here is a example of defining a TableGenerator and using within
GeneratedValue for an entity.
@Entity
@Table(name="Entity_TBL")
@TableGenerator(name="WebCartSequence",
schema="dbo",
table="WebCartSequence",
pkColumnName="Sequence_Name",
valueColumnName="Sequence",
pkColumnValue="MyEntityID")
public class MyEntity {
@Id
@GeneratedValue(strategy=GenerationType.TABLE,
generator="WebCartSequence")
private int id;
...
}
Again, this will not work with the same table definition as you currently
use. Based on the names in the example, you could add a column named
"Sequence_Name" to your existing table and set its value to "MyEntityID" and
that may do the trick.
-Jeremy
On Wed, Oct 13, 2010 at 12:41 PM, corstad <[email protected]> wrote:
>
> Greetings:
>
> I am attempting to migrate Entity Beans to OpenJPA. Each Entity Bean
> represents a single table in the DB. The Entity Beans are deployed on
> WebLogic 10.0 using WLS 8 version of the deployment descriptors. (I just
> work here).
>
> Each table has a corresponding sequence table with a single column named
> Sequence. The current DD for these use the following XML within the
> weblogic-cmp-jar.xml file for each weblogic-rdbms-bean defined.
>
> <automatic-key-generation>
> <generator-type>NAMED_SEQUENCE_TABLE</generator-type>
> <generator-name>WebCartSequence</generator-name>
> <key-cache-size>1</key-cache-size>
> </automatic-key-generation>
>
> The SQL used to create the sequence table is:
>
> CREATE TABLE [dbo].[WebCartSequence](
> [Sequence] [int] NOT NULL
> ) ON [PRIMARY]
>
>
> My question is what would the OpenJPA annotations look like to use this id
> generation strategy?
>
> Thanks,
>
> C.
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/Migrate-EntityBean-NamedSequenceTable-to-OpenJPA-tp5631958p5631958.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>