开发者

Spring and Hibernate: can't delete entry

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 li开发者_JAVA技巧nk. 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜