@Transient 在休眠状态下不工作

@Transient not working in hibernate

我正在使用休眠 4.1.9。 我的密码是

@Transient
private String ldapIdTemp;

包裹是

import javax.persistence.Transient;

仍在休眠查询中,它无法正常工作并将属性放入查询中。

查询片段的一部分(assetasset0_.ldapIdTemp 作为 ldapIdTemp16_0_,)

我不确定我做错了什么。

能否尝试为字段创建setter和getter,并在get方法中注解@Transient,如下:

private String ldapIdTemp;

 @Transient
 public String getLdapIdTemp() {
    return ldapIdTemp;
 }

 public void setLdapIdTemp(String ldapIdTemp) {
    this.ldapIdTemp = ldapIdTemp;
 }

很大程度上取决于您如何在 Entity 或 class 层次结构中 "integrated" 此字段。此外,field属性-access 可能会导致您的设置出现问题。请参阅此 post 了解详细说明。

对于你的情况,我可以想象你是:

  1. 实体继承策略中的混合字段和属性访问
  2. 在您的应用程序中使用基于 XML 的 Hibernate 配置。

在这两种情况下,JPA 2.0/2.1 specification 在第 2.3.1 节中明确指出:

It is an error if a default access type cannot be determined and an access type is not explicitly specified by means of annotations or the XML descriptor. The behavior of applications that mix the placement of annotations on fields and properties within an entity hierarchy without explicitly specifying the Access annotation is undefined.

请检查您的持久性 Entity class 是否有 字段属性基于注释。

检查 @Transient 批注的完全限定名称。 它可以来自 org.springframework.data.annotation.Transientjavax.persistence.Transient.

尝试使用javax.persistence.Transient.