First :
I am trying to create a sequence based id in order to increment automatically.
What i am wondering is that will it work ?
i am creating :
Code:
@Entity
@SequenceGenerator(
name="SEQ_STORE",
sequenceName="my_sequence"
)
public class Store implements Serializable {
private Long id;
private int i;
@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_STORE")
@Column(name="my_sequence")
public Long getId() { return id; }
public void setId(Long id){this.id = id; }
@Column(name = "i", nullable = false)
public int getI() { return i; }
public void setI(int i){ this.i = i; }
}
which create in the psql
Code:
Table "public.store"
Column | Type | Modifiers
-------------+---------+-----------
my_sequence | bigint | not nul
i | integer | not null
Indexes:
"store_pkey" PRIMARY KEY, btree (my_sequence)
.
but the normal usage of when creating the sequence is that the my_sequence should habe this modifiers as well
Code:
id | integer | not null default nextval('project_seq'::regclass)
which will auto increment.
So if i have setId then it will require me to give a value in order to increment the value manually.
Shouldnt there be no need for the setter ?
if i dont include the JBoss is requiring it.
What should i do for it ?
Second :
I am rather new at Hibernate if you havent already figured out. So i am building all in Jboss. When JBoss goes down or restarts the database will be droped and recreated when JBOss comes back online. How can i have the database to remain there and not be dropped and lossing the values ?
Stelios