在 JPA / EclipseLink 中使用 find API 获取非附加对象

Get non attached object with find API in JPA / EclipseLink

我想通过查找获得一个非附加对象。
类似于我使用 "eclipselink.read-only" 提示从命名查询中获得的内容。
有没有办法做到这一点,或者我需要通过 id 编写命名查询并使用提示?

您可以将查询提示传递给您的 find method,从而允许您传递 "eclipseLink.read-only" 提示:

HashMap props = new HashMap();
props.put("eclipselink.read-only", "True");
em.find(class, id, props);