-->
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.  [ 1 post ] 
Author Message
 Post subject: (How) can I inject data from a mapping file?
PostPosted: Wed May 25, 2005 4:53 pm 
Beginner
Beginner

Joined: Wed Feb 23, 2005 11:29 am
Posts: 26
We're using Hibernate 2.1.7c with the Spring Framework and are starting to make use of DbUnit in some integration tests. We're planning to ship with Hibernate 3.0, but we're relying on the maven plugin to do our schema-export and there's not a 3.0 version of it yet.

Anyway, we've been talking about how to apply the schema and populate it with minimal "startup" data for our app. Right now we're VERY early in our release cycle, so on build day someone just creates a blank database, does a build, applies the schema, and then there's a testcase we run that inserts all of the initial data and verifies that it can read it back. Then we check that database (Firebird 1.5.2) into source control and since we haven't written an installer yet, our release build copies the database along with the jar files, etc. and our Test group copies that database onto their machine.

Gross, huh? Well, we've talked about generating the database during our release build, but they really don't want the Firebird DB server running on the build machine. Mainly we've talked about creating and populating the database at INSTALL time. One person is in favor of exporting just the SQL schema FILE at build time, and having the installer create the database and send that schema file in, but that still leaves us with the question of how to insert the initial data. Since we are using Hibernate to hide all of the tables, etc. from the code, I would rather not maintain a separate .sql file that INSERTS the various pieces of data.

Worst case, I was thinking about writing a little tool to be run at install time that would call SchemaExport and then create the OBJECTS we need and let Hibernate write them to the database. That way there's no SQL fragment laying around that has to be synched with the latest schema, most of which is greek to us, because that's Hibernate's problem :-)

THE POINT:

While thinking through all of this, I thought about something you can do with the Spring Framework. They have an XML file that describes how various objects are related. It's loosely analogous to the Hibernate mapping files. Anyway, in the Spring XML file, you can define XML for properties of your classes, and those properties are "injected" into those classes at runtime via "setter" methods.

REALLY THE POINT:

This made me wonder - is there a way that I could` specify DATA in the mapping files??? It would be awesome if Hibernate could not only figure out the database STRUCTURE from the mapping files, but also notice that some initial data had been specified and go ahead and do those inserts. At that point we'd have everything we need in one place.

Is this possible? Could it be in the future??

-Jeff


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

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.