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

Questions by markantony   answers by markantony

Showing Answers 1 - 3 of 3 Answers

CrackHead

  • Aug 8th, 2011
 

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.

Give your answer:

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

 

Related Answered Questions

 

Related Open Questions