-->
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.  [ 5 posts ] 
Author Message
 Post subject: Generating SQL code without modifying database
PostPosted: Mon Aug 18, 2008 11:52 pm 
Newbie

Joined: Mon Aug 18, 2008 10:44 pm
Posts: 2
Hey,

Is it possible to generate SQL code using Hibernate without modifying the database? I know I can capture the SQL code with a logger but I want Hibernate to generate a bunch of SQL insert statements without needing the database installed.

The reason I want to do this is so I can generate the SQL on a different machine to the database (I don't currently have access to the computer running the database).

All the mapping files have been set up and work correctly.

Any help would be appreciated.


Kind Regards,


Jack Nickle


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 2:37 am 
Expert
Expert

Joined: Thu Jul 05, 2007 9:38 am
Posts: 287
You are not talking about create table and co (the Schema Export tool would help with those) but you are talking about insert, update and delete, right?

You could write your own jdbc driver that just logs the statements and returns some dummy values.

you could use a realy simple local database so that hibernate has the database as normal and simply log the statements. This should be way easier and more stable. But it doesn't fit your initial riquirements.

_________________
Please rate useful posts.


Schauderhaft: Softwaredevelopment, Projectmanagement, Qualitymanagement and all things "schauderhaft"


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 19, 2008 4:28 am 
Newbie

Joined: Mon Aug 18, 2008 8:40 am
Posts: 6
I'm not sure but I've seen this method on Eclipse.I haven't tried but it might be useful:

Code:
Criterion criterion;
.
.
.
.
.

criterion.toSqlString(Criteria arg0,CriteriaQuery arg1)



Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 7:05 am 
Newbie

Joined: Mon Aug 18, 2008 10:44 pm
Posts: 2
schauder wrote:
You could write your own jdbc driver that just logs the statements and returns some dummy values.


I think I will try this. :)

schauder wrote:
you could use a realy simple local database so that hibernate has the database as normal and simply log the statements. This should be way easier and more stable. But it doesn't fit your initial riquirements.


True I thought about doing this it just seems such a pain. I was hoping that Hibernate would provide an easy way. E.g. A fake mode where it would generate the insert statements etc without needing a database.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 7:53 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Have you tried using HSQLDB (http://hsqldb.org/)? It is a pure Java database engine that can be run in-process and with all tables in memory. Very useful for testing since everything goes away at the end of the test program. Don't forget to put the following line in your hibernate.properties file.

Code:
hibernate.hbm2ddl.auto = create-drop


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