如何解决@AdditionalCriteria 参数未在 EntityManager 中设置?
我尝试根据这里使用@AdditionalCriteria: https://wiki.eclipse.org/EclipseLink/Development/AdditionalCriteria
这是我的例子:
@Entity
@Table(name = "employees")
@AdditionalCriteria(":entryDate BETWEEN this.effectiveDate AND this.expirationDate")
public class EmployeeData {
@Id
@Column(name = "id")
private String id;
@Column(name = "effective_date")
@Temporal(value = TemporalType.DATE)
private Date effectiveDate;
@Column(name = "expiration_date")
@Temporal(value = TemporalType.DATE)
private Date expirationDate;
...
该实体引用自:
@Entity
@Table(name = "departments")
public class Department {
@Id
private long id;
@JoinColumn
private EmployeeData head;
...
然后查找:
final EntityManager em = emFactory.createEntityManager();
em.setProperty("entryDate",new Date());
Department department = em.find(Department.class,26151L);
EclipseLink 尝试应用预期的附加条件,但未找到该参数。 我收到以下异常:
Exception [EclipseLink-6174] (Eclipse Persistence Services - 2.7.7.v20200504-69f2c2b80d): org.eclipse.persistence.exceptions.QueryException
Exception Description: No value was provided for the session property [entryDate]. This exception is possible when using additional criteria or tenant discriminator columns without specifying the associated contextual property. These properties must be set through EntityManager,EntityManagerFactory or persistence unit properties. If using native EclipseLink,these properties should be set directly on the session.
好吧,正如我所见,我已通过 EntityManager 对其进行设置,如异常中所述。 在互联网上进一步查看似乎通常的方法是设置会话参数,在这种情况下我无法做到这一点。 我只是很困惑,因为文档中提到的方法似乎不起作用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。