Java 如何跟踪自定义JPA@查询获取的计算字段?
我创建了一个带有@ReadOnlyProperty注释的字段,以便跟踪计算出的字段值。然而,当我进行一个普通的findAll查询时,我收到一个SQL错误警告,该列(haschilds)不存在。我已经尝试删除GET方法,但它根本解决不了问题。我还尝试使用@Transient注释,但无法保存属性上的值Java 如何跟踪自定义JPA@查询获取的计算字段?,java,spring,hibernate,jpa,jpql,Java,Spring,Hibernate,Jpa,Jpql,我创建了一个带有@ReadOnlyProperty注释的字段,以便跟踪计算出的字段值。然而,当我进行一个普通的findAll查询时,我收到一个SQL错误警告,该列(haschilds)不存在。我已经尝试删除GET方法,但它根本解决不了问题。我还尝试使用@Transient注释,但无法保存属性上的值 @Entity @Table public class Parent extends BaseEntity { @Id @GeneratedValue(strategy = Gener
@Entity
@Table
public class Parent extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@OneToMany( fetch = FetchType.LAZY)
private List<Child> childs;
// Computed column that come from @Query annotation
@ReadOnlyProperty
private boolean hasChildren;
//Getters
//Setters
}
@实体
@桌子
公共类父级扩展BaseEntity{
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
私人长id;
私有字符串名称;
@OneToMany(fetch=FetchType.LAZY)
私人名单儿童;
//来自@Query注释的计算列
@只读属性
私生子;
//吸气剂
//二传手
}
尝试用JPAs@Transient注释该字段。这应该告诉它不要将其保留在数据库中。当我用JPAs@Transient注释该字段时,查询结果不会更改该属性。您是否尝试过类似haschilds(){return childs!=null&&childs.size>0}的操作?我简化了该类。事实上,我有3个类可以是这个“父”类的子操作系统。因此,我使用改进的查询来搜索是否至少有一个子项。