-->
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.  [ 3 posts ] 
Author Message
 Post subject: hbm2ddl and initial data loaded into database?
PostPosted: Tue Jan 18, 2005 7:42 pm 
Newbie

Joined: Tue Jan 18, 2005 7:32 pm
Posts: 1
I understand that Hibernate can generate the DDL for a database on the fly when it starts up via the hbm2ddl task, but is there some way to output some initialization data?

E.g., if you have a table listing the possible states and state-IDs, like NY, CA, MA, NH, etc. and the table looks like
table {
id : int
name : String
}
can you tell hbm2ddl to load up the table w/ some initial data when it creates it?

Also, do most hibernate users define their database by hand and then try to use Hibernate to access it? I've done this in the past, but I'm trying to see if I can use xdoclet to generate everything (including the table) from only Java source code...

thanks,

ken


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 18, 2005 7:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
No there is nothing builtin. But it should not be too difficult to write some utility functions that populate your tables.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 12:18 pm 
Beginner
Beginner

Joined: Tue Jan 18, 2005 9:37 am
Posts: 29
Location: The Netherlands
I've been working on this problem and if you are using ant then you can execute some insert statements like this: (put the insert statements in .sql files names fb_date*

Code:
<schemaexport 
properties="${conf.dir}/hibernate-firebird.properties"
         quiet="false"
         text="false"
         drop="false"
         delimiter=";"
         output="${gen.dir}/firebird-createtables.sql">
         <fileset dir="${gen.dir}">
            <include name="**/*.hbm.xml" />
         </fileset>
      </schemaexport>

      <!-- next thing: load initial data into db -->
      <sql
         driver="org.firebirdsql.jdbc.FBDriver"
          url="jdbc:firebirdsql://localhost:3050/D:/test.FDB"
          userid="sysdba"
          password="masterkey">

         <classpath refid="hbm2ddl.classpath" />
         <fileset dir="dbscript">
            <include name="fb_data*.sql" />
         </fileset>
      </sql>      


Of course it's better to create a class that does the data loading with Hibernate, because that way you have it in each possible database dialect.
Good luck.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.