I need to create a sequence for a property (that is not a primary key or part of a primary key) in my entity bean. It has the following requirements:
I'm trying to accomplish this in my entity bean code right now, but it doesn't seem to work.
@Entity @Table(name = "store") public class Store implements java.io.Serializable { ... @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "StoreIdSequenceGenerator") @SequenceGenerator(name = "StoreIdSequenceGenerator", sequenceName = "store_storeid_seq") @Column(name = "storeid", nullable = false) public int getStoreid() { return this.storeid; } ... }
As such, I'm attempting to use the JPA sequence generation facilities. Here's my table script:
CREATE TABLE store ( ... storeId SERIAL NOT NULL, ... )
I also create a sequence in the script:
ALTER SEQUENCE store_storeid_seq INCREMENT BY 1;
Again, storeId is not a primary key. The store table may have one or more records that contain the same storeId (the records are used in a way such that it may contain different recorded versions of a store, much in the way Wikipedia stores different versions of wiki entries). That's why storeId is not a primary key. I actually have another column that is a primary key column.
How can I do this? Perhaps I am looking something that is very simple. I would really like to avoid making a native query when I perform a persist. Is there anything in Seam that may help me with this issue?
I am currently using Seam 2.0.2 GA, PostGres 8.1, and JBoss 4.2.2 GA.
I heard these guys know more.