Now, I can incredibly easily implement a Session.exists() method, but I think it would encourage bad practice.
You can implement it yourself, of course, by doing a query like:
s.find("select mi.id from MyItem mi where mi.id = ?", id, Hibernate.LONG).size()==0
Troy McKinnon wrote:
http://forum.hibernate.org/old/914765.html talks around the issue I am
having but it doesn't really solve anything.
We start with an object manually created. >> MyItem myItem = new MyItem(id, name, desc);
I then check to see if it already exists. To determine if I want to do an update or a save.
>> MyItem fromDatabase = (MyItem)session.load(MyItem.class, dblItem.getId());
If fromDatabase existed, I want to update it with the data from myItem.
Because you can't just do an update(myItem) since fromDatabase is already loaded.
(Note: you can't do a update(myItem) even if you hadn't called the load - because the session doesn't recognise it to update.)
The only way I can see doing this now is to transfer the field values from myItem to fromDatabase.
(Note: using the reflect package to do this is fairly trivial - but just more work )
If there was some way to updateSimilar or updateFromClone or similar method that would allow an update with a different object, that would be nice to have.
Cheers
Troy
------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel