aspose file tools*
The moose likes Object Relational Mapping and the fly likes Creating Tables Automatically with Hibernate and JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Creating Tables Automatically with Hibernate and JPA" Watch "Creating Tables Automatically with Hibernate and JPA" New topic
Author

Creating Tables Automatically with Hibernate and JPA

rajasekhar kannamaneni
Greenhorn

Joined: Nov 05, 2010
Posts: 27
Hi All,

actually I have created Entity Beans which are used to create tables in mysql database, everything is working fine with transaction classes using entityfactory.

Now I need this functionality...when I deploy the EAR file in application sever JBOSS..it have to check whether the tables are existing in the database or not..if they are not present..it have to create the tables automatically..of course I have specified this function hibernate.hbm2ddl.auto=update in persistence.xml..but still not creating any tables which are not present in the database and not throwing any error also when ever I run the application server.

Can any one please give me an idea how to do this or please give me an example.

Thanks in Advance.


Best Regards,
Raja.
Harshavardhan Reddy
Greenhorn

Joined: Jul 23, 2009
Posts: 11
HI,

In Hibernate, you can do this by a property called hibernate.hbm2ddl.auto=update. this will update the database structure for every deployment. but this is not recommended in production.

possible options for this property are:

validate: validate the schema, makes no changes to the database.
update: update the schema.
create: creates the schema, destroying previous data.
create-drop: drop the schema at the end of the session.
rajasekhar kannamaneni
Greenhorn

Joined: Nov 05, 2010
Posts: 27
Harshavardhan Reddy wrote:HI,

In Hibernate, you can do this by a property called hibernate.hbm2ddl.auto=update. this will update the database structure for every deployment. but this is not recommended in production.


Hi,

thanks for the reply..but actually I have tried with this also, but still its not deploying and its not throwing any error also..can you please give me some example with entity beans or if you need I will send the classes I have developed by email...will wait for your reply..thanks in advance.
Harshavardhan Reddy
Greenhorn

Joined: Jul 23, 2009
Posts: 11
i'm sorry.... i haven't worked with JPA(EJB3). i'm currently working on Hibernate.. so i have no idea using the entity beans.
rajasekhar kannamaneni
Greenhorn

Joined: Nov 05, 2010
Posts: 27
but its inserting tables into default mysql database but not the entity classes..if any one knows please tell me.
 
Consider Paul's rocket mass heater.
 
subject: Creating Tables Automatically with Hibernate and JPA