-->
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: delete object wonth only primary key
PostPosted: Mon Jan 05, 2004 10:38 am 
Newbie

Joined: Mon Sep 01, 2003 10:40 am
Posts: 17
Why ther isn't a delete method like delete(Serializable pk) ? Where pk is a composite id o a primary key

Now, if want delete a object, I should before load it e after delete. So Hibernate makes two (or more) sql istance.

With my suggestion I can delete a object with this code:

MyComposuteid pk= new MyComposuteid ("ABC22",2);

session.delete(pk);


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 05, 2004 1:31 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Why don't you use session.delete("from MyObject m where m.id = 1234")?


Top
 Profile  
 
 Post subject: Here's how I do it
PostPosted: Wed Jan 07, 2004 5:30 pm 
Beginner
Beginner

Joined: Tue Sep 02, 2003 12:15 pm
Posts: 33
Here is what I am doing with my keys.

In this scenario, the you will need a way to lookup the persistent object from a key. In my case I call getDependentClass(Key obj) which returns the VO constructor that takes a Key. At that point, you just call delete on the persistent object which now has a primary key set.

public int delete(Key obj)
{
Constructor constructor = getDependentClass(obj).getDeclaredConstructor(new Class[] {obj.getClass()});
Object persistor = constructor.newInstance(new Object[] {obj});
session.delete(persistor);
}

This seems to work for me. Hope it helps a bit.

Nic


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