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.