-->
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: Persisting transient objects.
PostPosted: Thu Feb 05, 2004 3:32 pm 
Newbie

Joined: Fri Jan 30, 2004 5:10 pm
Posts: 7
Location: S
Hello.

I'm having a basic problem. Maybe this problem relies on how my application uses hibernate 2.1 with Tomcat 5.0.16.

I'm developing a simple WEB application that interacts with database throw hibernate framework.

So, supose the following scenario:

User at page ShowUserInformation.jsp clicks on button delete, which sends the user to another JSP (say, UserDelete.jsp) page that receives use userId as parameter.

At page UserDelete.jsp, I will use hibernate to delete the UserData (the table key is user_id) object from database, with something like this:

Code:
UserData user = new UserData();
user.setUserId(request.getParameter("userId"));
tx = session.beginTransaction();
session.delete(user);
tx.commit();


However,at this point, it throws an exception that user object is not persistent since some of its atributes are "not-null".

I wonder, the only way to delete this object from database is to use a custom delete HSQL statement? Of course, I can get the persistent object from database and them delete it.

I understand that my approach might be wrong. How would be a good aproach for solving this "problema" since I don't wanna "go" again to the dabase to get the persistent user and them delete him.

I hope I made my self clear.

Regards,

Flavio Matiello


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2004 3:54 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No, but why delete(HQL) is so hard ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2004 8:56 am 
Newbie

Joined: Fri Jan 30, 2004 5:10 pm
Posts: 7
Location: S
No, its not that hard.

However, Hibernate could provide a method like delete(keyParam),
just like we use on load operation.

Maybe there's a way to do this that I'm not aware of.

Imagine if my table has a primary key based on 4 colums.
I must provite a HQL statement with four parameters and four types, which could be replaced by a singe EntityPK object. Know what I mean?

Regards,

Flavio Matiello


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2004 9:32 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This has been discussed either on the forum or in JIRA. Have a look. I can remember Gavin wasn't fond of.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2004 5:18 pm 
Newbie

Joined: Fri Jan 30, 2004 5:10 pm
Posts: 7
Location: S
Yes, I found it on JIRA emmanuel.

Just another thing, according to the hibernate sql logs generated, when I execute a delete with HQL query, it in fact, executes a select and a delete right? I mean, It interact 2 times with the database....

Following the above reasoning, what if I execute a delete with a HQL query to delete a lot of records, it would interact several times with the database, or just two times.

Thanks in advance,

Fl


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2004 5:21 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
All objects have to be loaded (at least lazily) so cascading and lifecycle operations can be applied before deletion. Mass deletes (and updates) are not a good usecase for Hibernate (and ORM in general). Those usecases are usually rare in an application, if you need best performance, use a direct JDBC SQL call or a stored procedure.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.