在Spring Hibernate中调用@Transient方法 [英] @Transient method call in Spring Hibernate

查看:188
本文介绍了在Spring Hibernate中调用@Transient方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Pojo类,其中创建了一个未与DataBase Table进行映射的字段。
所以我必须声明字段声明和setter和getter方法@Transient,否则它会显示一个错误。

  @Transient 
private String docHistoryString =;

@Transient
public String getDocHistoryString(){
return docHistoryString;
}

@Transient
public void setDocHistoryString(String docHistoryString){
this.docHistoryString = docHistoryString;
}

现在,我的问题出现在控制器中。我在这个瞬态字段中设置了一些值,但是当我尝试在视图(JSP)中使用EL来访问这个变量时,它没有提供价值。我认为这是因为我在get方法中使用@transient注释。 所有Hibernate注释,包括 @Transient 都必须按照以下方式应用: 访问类型。默认情况下,它将与应用 @Id 相同。也就是说,如果您在字段上放置 @Id ,则必须将 @Transient 应用于该字段。如果将 @Id 应用于getter方法,则必须应用 @Transient 方法。 Setter方法总是被忽略。



尽管(根据文档)它可以被定制,所以确保有人不会对访问类型做一些奇怪的事情。


I have one Pojo class in which I create one field which is not mapped with DataBase Table. So i have to declare the field Declaration and setter and getter method @Transient, otherwise it would have shown an error.

@Transient
private String docHistoryString="";

@Transient
public String getDocHistoryString() {
    return docHistoryString;
}

@Transient
public void setDocHistoryString(String docHistoryString) {
    this.docHistoryString = docHistoryString;
}

Now, my problem is in the controller. I have set some value in this transient field but when I try to access this variable using EL in view(JSP) it is not giving value. I think this is becouse I used the @transient annotation in get method.

解决方案

All Hibernate annotations, including @Transient must be applied according to access type. By default it will be the same way as @Id applied. That is if you place @Id on a field you must apply @Transient to the field. And if you apply @Id to getter method, you must apply @Transient method. Setter methods are always ignored.

It can be customized, though (per documentation), so make sure that someone didn't do something strange with access types.

这篇关于在Spring Hibernate中调用@Transient方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆