在更新之前选择Hibernate [英] Hibernate select before update

查看:117
本文介绍了在更新之前选择Hibernate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的工作中,我使用exidirect的spring,服务器端的hibernate和客户端的extjs。当我发布一个表单时,在服务器端弹簧将其转换为实体。
实体有一个id字段,假设更新操作。
我打电话给service save 方法,但是改为一个sql update 查询,我得到许多选择查询,然后更新。这需要很多时间。这个操作不需要。
我看到类似的问题,并尝试使用持久方法。
这种情况​​我得到错误:传递给持久化的分离实体。

我没有足够的休眠经验。可能是我需要配置相关实体​​(OneToMany,ManyToOne和级联类型)。实体由Spring roo工具生成。



任何建议?
谢谢。

解决方案

这不是您的问题的最终答案,但我希望它可以作为一个高当你用Spring创建实体时,该实体被分离,Hibernate执行这些SELECT语句,因为它需要在持久化之前附加你的实体。此外,据我所知,任何附加实体的尝试都会触发SELECT语句。因此,我坚信没有任何方法可以在没有这些SELECT语句的情况下保存/保留分离的实体(我可能在此处错误)。



<如果您担心性能问题,可以尝试在应用程序中添加一些缓存功能。此外,您还可以将JDBC解决方案仅用于性能受到影响的操作。


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.

解决方案

This is not a final answer for your question but I hope it can work as a high level guideline.

When you create an Entity with Spring, that Entity is detached and Hibernate performs these SELECT statements because it needs to attach your Entity before persisting it. Additionally, as far as I know any attempt to attach an Entity is going to trigger SELECT statements. Therefore, I strongly believe that there is not any way to save/persist your detached Entities without these SELECT statements (I might be wrong here).

If you are concern about performance you can try adding some cache functionality to your application. Moreover, you can also include JDBC solutions only for operations which are suffering with performance.

这篇关于在更新之前选择Hibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆