开发者

hibernate save object

For an application, I am using Struts2, hibernate and spring for injection. Any time I save an object to DB, I HAVE to do inside the Se开发者_StackOverflow中文版rivces class(session injected here). In any action class, if i obtain current session and save it, it doesn't save the object to the database. Although, I do see insert into..... in the logs. why is that?


I assume you are not doing transaction handling. You will not see a record in the database until the transaction is committed.

I guess Spring manages the transaction automatically in your service class. However if you use the session directly you also need to start/commit the transaction in your code.

See http://docs.jboss.org/hibernate/stable/core/reference/en/html/transactions.html for more details

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜