This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA (hibernate) good practice with table initialization

 
Kirill Levan
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Kirill Levan
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic