-->
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: Update table without losing the data
PostPosted: Mon May 16, 2005 12:44 pm 
Newbie

Joined: Mon May 16, 2005 12:18 pm
Posts: 2
Hi All,

I created a project with Hibernate as ORM. At this time i'm using this project, but i created a newer version of it. Is there a posibillity to update the database without losing all the data ?

Example :

I have a client.


Code:
public void Client {

   private long id;
   private String name;

   /**
    *@hibernate.id column="id" generator-class="identity" unsaved-value="0"
    */
    public long getId() {
   return id;
    }
   
    public void setId(long id) {
              this.id = id;
    }

    /**
     * @hibernate.property
     */
     public String getName() {
        return name;
     }

     public void setName(String name) {
   this.name = name;
     }
}

This will create a table with an id and a name.

Now i want to put there an extra field like e-mail, without losing all the data.

Can Hibernate handle this update ? Or, should i write for this some small update program ? Or, does anyone have a tool wich can compare the old version of database structure with the new one, and change it...

thanks in advanced

Alain


Top
 Profile  
 
 Post subject: Re: Update table without losing the data
PostPosted: Mon May 16, 2005 1:03 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Alain_Janssens wrote:
Hi All,

I created a project with Hibernate as ORM. At this time i'm using this project, but i created a newer version of it. Is there a posibillity to update the database without losing all the data ?

Example :

I have a client.


Code:
public void Client {

   private long id;
   private String name;

   /**
    *@hibernate.id column="id" generator-class="identity" unsaved-value="0"
    */
    public long getId() {
   return id;
    }
   
    public void setId(long id) {
              this.id = id;
    }

    /**
     * @hibernate.property
     */
     public String getName() {
        return name;
     }

     public void setName(String name) {
   this.name = name;
     }
}

This will create a table with an id and a name.

Now i want to put there an extra field like e-mail, without losing all the data.

Can Hibernate handle this update ? Or, should i write for this some small update program ? Or, does anyone have a tool wich can compare the old version of database structure with the new one, and change it...

thanks in advanced

Alain


Why do you think you will lose your data ? The only way hibernate will ever cause a loss of data would be if you specify the Configuration property hibernate.hbm2ddl.auto=create-drop. But in this case, you'll lose your data whether you change the table structure or not.

If you are having hibernate generate your database, and you use hibernate.hbm2ddl.auto=update, it will modify the tables and leave your data in tact.


Top
 Profile  
 
 Post subject: Re: Update table without losing the data
PostPosted: Thu May 26, 2005 1:01 pm 
Newbie

Joined: Mon May 16, 2005 12:18 pm
Posts: 2
pksiv wrote:

Why do you think you will lose your data ? The only way hibernate will ever cause a loss of data would be if you specify the Configuration property hibernate.hbm2ddl.auto=create-drop. But in this case, you'll lose your data whether you change the table structure or not.

If you are having hibernate generate your database, and you use hibernate.hbm2ddl.auto=update, it will modify the tables and leave your data in tact.


And where can i change this ??


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.