This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes JPA (hibernate) good practice with table initialization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "JPA (hibernate) good practice with table initialization" Watch "JPA (hibernate) good practice with table initialization" New topic
Author

JPA (hibernate) good practice with table initialization

Kirill Levan
Greenhorn

Joined: Feb 28, 2013
Posts: 4
Hello!

I'm a new one in JPA and I have a question about good practice.
The question is - what is good way to create tables and update them in big project? Especially in production.
As I found - using hbm2ddl auto updates in production is a bad way. Instead of it I'm looking for good approach for initialization my DB using JPA.
It shouldn't depends on concrete JPA implementation and DBMS (at least it should successfuly work with PostgreSQL and MySQL).

So, I'm looking for good solution for first initialization for my database with JPA (JPQL) way
Florin Vasile
Greenhorn

Joined: Feb 14, 2013
Posts: 8
Hello Kirill,

Kirill Levan wrote:

The question is - what is good way to create tables and update them in big project? Especially in production.
As I found - using hbm2ddl auto updates in production is a bad way. Instead of it I'm looking for good approach for initialization my DB using JPA.
It shouldn't depends on concrete JPA implementation and DBMS (at least it should successfuly work with PostgreSQL and MySQL).



JPA specification doesn't standardize the DDL generation but most of the providers support it (of course, in their own way).

It should only be used while prototyping the application and you shouldn't use it to update the schema in production. Instead you should create some SQL DDL statements and run those, and of course provide the specific mapping in JPA.


Kirill Levan wrote:

So, I'm looking for good solution for first initialization for my database with JPA (JPQL) way



What initialization do you need, schema or data?

FVasi
OCPJP 6, OCEJPAD 6
Kirill Levan
Greenhorn

Joined: Feb 28, 2013
Posts: 4
Florin Vasile wrote:
What initialization do you need, schema or data?


At first it is related to schema initialization.
But it would be interesting to know a good practice in data initialization too.
Kirill Levan
Greenhorn

Joined: Feb 28, 2013
Posts: 4
Florin Vasile wrote:
Instead you should create some SQL DDL statements and run those, and of course provide the specific mapping in JPA.

Can this SQL DLL statements be created with some platform-independent way? Can we use JPQL for it?
Florin Vasile
Greenhorn

Joined: Feb 14, 2013
Posts: 8
Kirill Levan wrote:
Florin Vasile wrote:
Instead you should create some SQL DDL statements and run those, and of course provide the specific mapping in JPA.

Can this SQL DLL statements be created with some platform-independent way? Can we use JPQL for it?


There is no platform-independent way to do this with JPA. JPQL supports only update, delete and select statements. There are no DDL statements or even insert statements.

For data initialization i guess you could create a method that runs on the start of the application and creates a number of entities and persists them.

 
Consider Paul's rocket mass heater.
 
subject: JPA (hibernate) good practice with table initialization
 
Similar Threads
JPA and Spring
General Deployement Questions...
How to connect Servlets and EJBs
How to add a JPA project to Web Project?
How to connect Servlets and EJBs