更新时间:2023-11-22 23:46:34
AFAIK要删除这些多余的查询,请删除对@Transactional
批注的所有修饰符.将隔离级别限制为READ_COMMITED
所要付出的代价是,Hibernate将需要执行额外的查询以确定数据库是否处于脏状态.对于90%的情况,这些修饰符是不必要的. Hibernate非常擅长确保您的数据干净,而无需尝试添加这些限制.
AFAIK to remove those extra queries, remove all your modifiers to your @Transactional
annotations. The price you pay for restricting your isolation level to READ_COMMITED
is that Hibernate will need to perform extra queries to determine if the database is in a dirty state. For 90% of cases, these modifiers are unnecessary. Hibernate is very good at ensuring that your data will be clean without you trying to add these restrictions.
如果您绝对有必要确保隔离为READ_COMMITTED
,则您对多余的查询将无能为力.
If it is absolutely necessary for you to ensure that your isolation is READ_COMMITTED
, you can't do anything about the extra queries.
仅出于摆脱这些查询的原因而移至StatelessSession
是一个坏主意.确实,使用StatelessSession
的唯一有效理由是对插入的大批数据进行了插入,而您知道这些数据在插入发生时将不会被读取.
Moving to a StatelessSession
just to get rid of those queries is a bad idea for exactly the reason you pointed out. Really, the only valid reason to be using a StatelessSession
is for large batch inserts of data that you know won't be read while the insert is occuring.