These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Two Questions : Sequence and Persistence.
PostPosted: Sat May 31, 2008 2:23 pm 
Newbie

Joined: Sat May 31, 2008 2:06 pm
Posts: 4
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


Top
 Profile  
 
 Post subject: Re: Two Questions : Sequence and Persistence.
PostPosted: Mon Jun 02, 2008 2:23 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
stevoo wrote:
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 ?

In you Hibernate configuration you have to disable the automatic drop and recreate of the database. Something like this:
Code:
hbm2ddl drop="false"
              create="false"
              export="false"
                   


Carlo
-----------------------------------------
please credit me if this helped you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 10:17 am 
Newbie

Joined: Sat May 31, 2008 2:06 pm
Posts: 4
pablo, i was thinking about that i just wasnt sure if it would work as i keep on updating the datase so when i replace the jar file will it drop and recreate the tables ?


To my firsts question:
Will it be better to create the session and during create to get the next value of my sequence something like
table.get_nextVal();
or whatever ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.