• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Relations like Many to One in Hibernate and Database?

 
Sri Dharan
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do we represent Many to One/Many to Many relations of Hibernate in Database(Oracle)?

Do we need to write the hibernate code based on Database table or inversely? (i.e Which is first , creation of the tables in Database then Hibernate code (or) Creation of POJO classes in Hibernate then creation of tables?
 
Christian Dillinger
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can do it the way you like. Hibernate can create a schema from it's mapping files. But I would recommend that you (or your DBA) create tables first. In your development environment you can do it, but in production I think no DBA will let you generate tables. (Esp. in Oracle where you often want to put data and index into different tablespaces)
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your POJOs are mapped properly, you can just do a SchemaExport, and the underlying database will be created for you:



http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=02validatingthehibernateenvironment

It's a great way to create your database if you have the permissions to do it.

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic