Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[SOLVED] [JPA-HIBERNATE] How to populate a table at start time

 
Roberto Lopez Lopez
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there.

I'm working at a project which uses JPA (Hibernate 3) as ORM technology. Everything is running OK, but we need to check if the countries table is empty or not. If it's empty, we have a method which populates it.

We want Hibernate to check this just when it starts up (e.g. after every jBoss restart). Is there any init() method or anything similar that could help us?

Thank you in advance.

[ October 07, 2008: Message edited by: Roberto L�pez L�pez ]
[ October 07, 2008: Message edited by: Roberto L�pez L�pez ]
 
Ramesh Srinivasan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Roberto L�pez L�pez:
Hi there.


We want Hibernate to check this just when it starts up (e.g. after every jBoss restart). Is there any init() method or anything similar that could help us?

Thank you in advance.

[ October 07, 2008: Message edited by: Roberto L�pez L�pez ]


You need to manage it with your Hibernate Session Factory to create tables during the startup of your server.
 
Roberto Lopez Lopez
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice tip, question solved.

Thank you Ramesh Srinivasan!!!
 
Kuladip Yadav
Ranch Hand
Posts: 162
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Roberto L�pez L�pez:
Nice tip, question solved.

Thank you Ramesh Srinivasan!!!


I have same query.
Will you please explain me
How do you solved it ?

Thanks
 
Roberto Lopez Lopez
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't solved my problem exactly in the way Ramesh Srinivasan suggested, but he gave me an idea... let me explain.

I already had a method which populates the static-data in my database (like the countries table). I'm also using facade and factory patterns, so I did as follows:



As me is an static attribute, the default constructor will be called just once...

I hope it's useful to you...
[ October 08, 2008: Message edited by: Roberto L�pez L�pez ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic