问题描述
我有一个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方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!