Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
环境:Java,休眠
假设我执行两个数据库查询:
伪代码:
Author au1 = execute_query_1 Author au2 = execute_query_2
并假设这两个查询从数据库返回相同的记录。
是否可以安全地说该声明:
au1.equals(au2)
会返回真实的??
是的,如果您使用同一会话执行查询。Hibernate 将简单地从缓存中获取它。
如果 object Author 覆盖 equals() 方法是完全安全的。如果没有,则与键入 au1 == au2 相同,可以返回任何内容,这可能是两个不同的实例。好办法是为它写一个自动化测试