views:

47

answers:

2

Hi everyone,

I stuck with entry deleting an entry from DB. I have Hibenrnate integrated with spring. RDMS is HyperSql and application server is

Tomcat 6. For dependency management I use maven and for development I use Eclipse with maven plug-in.

Hibernate is in version: 3.3.2.GA
Spring is in version: 3.0.3.RELEASE
HyperSql is in version: 2.0.0

My problem is as follows. First, I store entry into database using merge. This entry is request for user's registration. After entry is stored into db, I send email to that new user. This email contains confirmation link. This is used to verify users email address he/she entered making registration request. After user goes to link, which I sent in email, user is asked for credentials and if credentials are ok, the registration request is confirmed and should be deleted from DB. I'm trying to delete this entry simply using delete(Object) method. Everything seems to be just fine, until I try to access to same request I deleted few moments ago. This entry is not actually deleted and in log I find next message:

handling transient entity in delete processing.

I tried to flush session and to clear it, but it didn't done anything good.

Session factory is: org.springframework.orm.hibernate3.LocalSessionFactoryBean

Any help will be appreciated.

Best regards, Tiho

A: 

Transaction needs to be commited.
Have a look at these docs about Transaction management:

Managing Transactions with Hibernate
Spring Transaction Reference

org.life.java
thanks for links. I'll read them and add transaction management command as needed.
Tiho
The spring link was an ancient version (2.0), I changed that to the current version (3.0.3)
seanizer
ok Thanks seanizer :)
org.life.java
After some reading about spring's transactional management and increasing log level, I can confirm that transaction is committed after delete action, but entry is accessible anyway.I saw that link is to spring 2.0 so I read documentation form version 3.0.x.I will appreciate any other hint
Tiho
If you need log entries, I will post them.
Tiho
A: 

Do you load the object in the same session you delete?

You should, because that way the object gets to be managed by that session. You cannot merge the object somewhere, pass it on, and then plainly delete it. The transaction has been closed and the object is then transient (unmanaged). In short, just before you delete, load the object. You have the id so it shouldn't be difficult.

EDIT

Moved the comment with the working answer into the question.

extraneon
I use org.springframework.orm.hibernate3.HibernateTransactionManager for transaction managment. It looks like I need to learn more about transaction management in spring. I'll read more about this.Thank for questions which directed me in right way.
Tiho
I marked method which deletes this entry as @Transactional(propagation=REQUIRES_NEW) and application behaves same as without this change.
Tiho
@Tiho Do you load the object in the same session you delete? You should, because that way the object gets to be managed by that session. You cannot merge the object somewhere, pass it on, and then plainly delete it. The transaction has been closed and the object is then transient (unmanaged). In short, just before you delete, load the object. You have the id so it shouldn't be difficult.
extraneon
@extraneon Thank you a lot. This was awesome proposition and it works. Thanks again! You helped a lot.
Tiho
@Tiho I'm glad I could explain sufficiently well what I thought was wrong. Not that easy to put into words :) I'm going to update the answer with the text in my comment, so others can enjoy it too.
extraneon