-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Hibernate init DB
PostPosted: Thu Jan 10, 2008 10:32 am 
Regular
Regular

Joined: Wed May 02, 2007 2:42 pm
Posts: 101
Hey,

I work with Jboss and ejb3.

Hibernate is generate the tables in case that they dont exists during the server startup.

I need to insert some entries after the schema was created and before the application is started.
Does any one know how to do this?

I cant use jboss-sar because the database wasnt created when the sar loaded.

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 10, 2008 10:36 am 
Regular
Regular

Joined: Thu Oct 13, 2005 4:19 am
Posts: 98
Inject the EntityManager(Factory) in an bean that listens to server startup (in spring that would be a IntializingBean, idunno what interface it is in EJB3).
Normally the EntityMangerFactory should be created by then and the database should be populed with it's tables by hibernate, so you can use for example dbunit to insert the starting data then.

_________________
http://www.ohloh.net/accounts/ge0ffrey


Top
 Profile  
 
 Post subject: You need in this case that the startup will know the
PostPosted: Thu Jan 10, 2008 10:59 am 
Regular
Regular

Joined: Wed May 02, 2007 2:42 pm
Posts: 101
persistence unit and my persistence unit scan for 4 jars that the startup donst know all.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 10, 2008 1:58 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you can use a file named /import.sql to do that. it will be read and executed by hibernate

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Thanks can you give me a reference to an example
PostPosted: Thu Jan 10, 2008 2:23 pm 
Regular
Regular

Joined: Wed May 02, 2007 2:42 pm
Posts: 101
Thank you


Top
 Profile  
 
 Post subject: I figure out how to do this, but
PostPosted: Thu Jan 10, 2008 3:19 pm 
Regular
Regular

Joined: Wed May 02, 2007 2:42 pm
Posts: 101
There is problem to hibernate in case that the insert is not written in one row.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 4:12 am 
Regular
Regular

Joined: Thu Oct 13, 2005 4:19 am
Posts: 98
emmanuel wrote:
you can use a file named /import.sql to do that. it will be read and executed by hibernate

Nice :)
Any way to rename that file?

Is it possible to execute some java code too? Like for example a class that calls DBUnit?

_________________
http://www.ohloh.net/accounts/ge0ffrey


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 11, 2008 6:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no the file cannot be renamed, it's a simple way to execute SQL operations at SF startup, that's it.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.