Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hiberante annotations

 
rani vini
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is Hibernate will create schema also? Say I am writing one POJO class TEST and there is no table with name "TEST".
The following will create Table "TEST" in DB?
@Entity
public class Test {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
long id;
private String chin ;
private String emr ;

public void setId(long id) {
this.id = id;
}

public long getId() {
return id ;
}

public void setChin(String chin) {
this.chin = chin;
}

public String getChin () {
return chin;
}

public void setEmr(String emr) {
this.emr = emr;
}

public String getEmr () {
return emr;
}

}
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate can generate DDL. See the configuration options for hibernate.hbm2ddl.auto.
 
Bhagat Singh Rawat
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add the following line in your hibernate.cfg.xml and execute your application:
<property name="hbm2ddl.auto">create</property>

But the disadvantage of this property is it will create schema every time whenever you restart your application. You will be lost your stored data. If you don't want to use this property then just change it to:
<property name="hbm2ddl.auto">none</property>
 
rani vini
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanq Bhagat
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhagat, are you aware this configuration option accepts a value of "update" too?
 
Bhagat Singh Rawat
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:Bhagat, are you aware this configuration option accepts a value of "update" too?


Yes Paul here is the list:

validate | update | create | create-drop

I know why are you asking this question because I am using none in my above example
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic