Hello, I'm writing a project that will make use of mySQL or Derby (it must work in both situations). To solve this I'm using Hibernate and it works nicely, but for a situation: I've a couple of tables that contain cities and towns, with data related so that if i know the town I can join and get the county, state and zip code. These tables are full of thousands of rows. I'm not using Hibernate to handle them, but plain JDBC. These table are not going to change in time, they're just for reference and for autocompletion needs. So what is the best way to reproduce this tables in both mySQL and JavaDB? Specifically they must be generated on the first start of the app. I thought of creating a special format and save everything to text files, then on first run they will be inserted in the db... but is there a way to save some coding and use a tool that is already there? I found many saying to use CSV, but it is not the case as it doesn't keep information like the type of column or length. Same for the XML that my mySQL tool (sqlYog) produces. Do you have other suggestions or tools?
A:
I would use Hibernate, and map the entities as mutable=false. Hibernate is then not permitted to change anything. Create the schema using the standard Hibernate means, then use IStatelessSession to insert the records, ensuring you've enabled batching.
James L
2010-02-18 16:49:38
Hmmm... yes but how do I save the table data?
gotch4
2010-02-19 10:42:26
Load the records from your text file and perform statelessSession.Insert on each one. You will already have the table definition in your mapping file.
James L
2010-02-20 18:41:02