-->
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.  [ 6 posts ] 
Author Message
 Post subject: Insert through a HQL
PostPosted: Thu Oct 06, 2005 10:04 am 
Newbie

Joined: Thu Oct 06, 2005 9:57 am
Posts: 5
Hi,

Is there a way to make an entry in a table without using session.save().

Thanks in advance.

From,
Santo.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 06, 2005 11:05 am 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
Yup, but you're going to have to use native SQL:

session.createSQLQuery("INSERT INTO ...").executeUpdate();


Top
 Profile  
 
 Post subject: Re: Insert through a HQL
PostPosted: Thu Oct 06, 2005 11:13 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
incarnateX wrote:
Hi,

Is there a way to make an entry in a table without using session.save().

Thanks in advance.

From,
Santo.


Just curious... if you're using Hibernate, why would you want to insert a row without using the Session.save() method ?

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 06, 2005 11:55 am 
Beginner
Beginner

Joined: Tue Aug 17, 2004 11:27 pm
Posts: 24
session.saveOrUpdate()

:-)


Top
 Profile  
 
 Post subject: Re: Insert through a HQL
PostPosted: Sat Oct 08, 2005 8:04 am 
Newbie

Joined: Thu Oct 06, 2005 9:57 am
Posts: 5
pksiv wrote:
incarnateX wrote:
Hi,

Is there a way to make an entry in a table without using session.save().

Thanks in advance.

From,
Santo.


Just curious... if you're using Hibernate, why would you want to insert a row without using the Session.save() method ?


The save() method accepts a detached object and persists it to the database. In my case, the object Iam creating needs a lot of child objects to be loaded which results to a lot of overhead which I want to avoid. Just in case you need an example......
Code:
class A{

  /* persistent child*/
  B b;

  public A(B b){

    this.b = b;
  }
}

----------------------------
_b = session.load(...);
A _a = new A(_b);
session.save(_a);


In this case in order to persist "_a" I first need to load "_b" which is something I wish to avoid. That's the reason why I was wanting to INSERT directly through HQL.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 08, 2005 8:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
So then use proxies for those "child objects". Then session.load() will not hit the database. So many misconceptions, so little time ;)

In Hibernate3 HQL now has an INSERT-SELECT statement. Currently it is serverely hampered by the fact that it cannot handle associations; that will be rectified before 3.1 goes final though.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.