GeekInterview.com
Series: Subject: Topic:
Question: 3 of 38

How do we create new table apart from mapping with existing table ?

Asked by: markantony | Member Since Jan-2009 | Asked on: May 12th, 2011

View all questions by markantony   View all answers by markantony

Showing Answers 1 - 1 of 1 Answers
CrackHead

Answered On : Aug 8th, 2011

View all answers by CrackHead

Hibernate automatically creates new tables if there are corresponding POJOs.

If you know how to write/read to/from an existing table using Hibernate, then you can easily create a table.
Step#1: Create the POJO class for the table to be created.
Step#2: Write the (NewTable).hbm.xml file of this table/entity.
Step#3 (optional): Change the property "hbm2ddl.auto" value to "create" in the hibernate.cfg.xml (generally we use update).
Step#4: Add the mapping resource of the NewTable in hibernate.cfg.xml
Step#5: Write a sample program to add data to your NewTable... to make sure it's working.

If all the configuration stuff is good and the execution goes as expected, check the database for the table and we should be able to find it with the sample records added.

Yes  1 User has rated as useful.
  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.