-->
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: changing attribute name creates new column on Database
PostPosted: Thu May 10, 2012 7:07 pm 
Newbie

Joined: Thu May 10, 2012 12:13 pm
Posts: 2
Hi!

Let´s first show the example:

Code:
@Entity
public class Person{

       @Column(nullable=false,unique=true)
       private String name;

}


It creates the column NAME on database.

But when i change the attribute name, (myname) a fictional example, it creates a new column.

I would like to change the attribute name (in java code, or with the anotation columnname ), and

change only the name of the column on database automatically, of course, with the same data.

Is that possible?

Thank You

The new hibernate user :)


Top
 Profile  
 
 Post subject: Re: changing attribute name creates new column on Database
PostPosted: Fri May 11, 2012 2:17 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
I would like to change the attribute name (in java code, or with the anotation columnname ), and
change only the name of the column on database automatically, of course, with the same data.
Is that possible?


No, at least not automatically.

As I'm informed Hibernate does't provide automatic schema migrations.
There exists property

hibernate.hbm2ddl.auto = update

but this is still experimental and not recommended for production use.

What you can do, is launching your hibernate with property:

hibernate.hbm2ddl.auto drop,create

This will erase and rebuild your schema on database, so the old column "name" dissapperas.
But obviously in this way you will lost all data.


Top
 Profile  
 
 Post subject: Re: changing attribute name creates new column on Database
PostPosted: Fri May 11, 2012 7:41 am 
Newbie

Joined: Thu May 10, 2012 12:13 pm
Posts: 2
Thank you for the answer.

In this way, i have to create each "version" of the system, a "ALTER TABLE" string, for each change on hibernate attribute names.

It would be nice if hibernate stores the attribute x column reference.

Thank you.


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.