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: Hibernate insert SQL
PostPosted: Fri Jul 07, 2006 10:44 pm 
Newbie

Joined: Fri Jul 07, 2006 10:39 pm
Posts: 1
I have a batch of insert SQLs in a text file. How can I get hibernate to load this set of SQLs in the database? One way of doing that is to create an object for each of the insert SQLs and then call session.save(). However, I was wondering of hibernate has any support for custom inserts with values?

thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 09, 2006 2:16 am 
Beginner
Beginner

Joined: Mon Jul 26, 2004 4:29 pm
Posts: 45
Location: TX, USA
Take a look at Section 17.4 of the reference manual.

If all else fails you can call session.connection() and use jdbc code to execute the inserts from your text file.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 10, 2006 3:59 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
In fact, in you need to format sql at your convenience, as mojarrell said, see
http://www.hibernate.org/hib_docs/v3/re ... erysql-cud

If you want to do batch insert, then see :
http://www.hibernate.org/hib_docs/v3/re ... ch-inserts

But I'd ask myself of the interest of loading these sql statement as objects... If you are not sure of the qualities of these insert queries (null fields, or else), then maybe it could be an idea. But if you know these queries are ok, then don't load them as object : throw them directly against the db using the underlying jdbc connection.

What are these queries designed for ? Do you have to execute it regularly or only once after the creation of the db. If second choice, then it's another argument no to try and load them as entities. If it's designed to be called many times and/or change sometimes, then in fact it could be a good idea to load them as objects before saving it...

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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.