5

In my work i'm using spring with exidirect, hibernate on the server side and extjs on client side. When i post a form, on the server side spring converts it to the entity. Entity has a id field, that supposes update operation. I'm calling service save method, but instead one sql update query i get many many select queries and just then update. It takes much time. And there is no need for this operation. I was looking similar questions and was trying to use persist method. This case i get error: detached entity passed to persist.

I do not have enough experience of hibernate. May be i need to configure related entities (OneToMany, ManyToOne and cascade types). Entities are generated by Spring roo tool.

Any suggestions ? Thank you.

4

2 回答 2

7

这不是您问题的最终答案,但我希望它可以作为高级指南。

当您使用 Spring 创建一个实体时,该实体被分离并且 Hibernate 执行这些 SELECT 语句,因为它需要在持久化之前附加您的实体。此外,据我所知,任何附加实体的尝试都会触发 SELECT 语句。因此,我坚信如果没有这些 SELECT 语句,就没有任何方法可以保存/持久化分离的实体(我在这里可能错了)。

如果您担心性能,您可以尝试向您的应用程序添加一些缓存功能。此外,您还可以仅针对性能受到影响的操作包含 JDBC 解决方案。

于 2013-04-30T18:22:02.497 回答
0

向实体添加 @SelectBeforeUpdate(false) 注释。

于 2016-08-05T18:11:58.263 回答