英文:
Why does hibernate give me this error when I put the transient tag?
问题
我正在尝试修复Kiuwan指出的漏洞。
问题是其中一个漏洞是将"Transient"类型添加到"Date"类型的变量中,当我这样做时,会出现以下错误。
Caused by: org.hibernate.AnnotationException: com.pack.keys.MyClassKey没有持久性id属性:com.pack.logic.MyClass.id
如果我在"Date"类型变量中不使用"transient"关键字,则不会显示错误,我的项目可以编译。
MyClass
@Table(name = "tablename")
@AllArgsConstructor
@NoArgsConstructor
@Data
public class MyClass{
@EmbeddedId
private MyClassKey id;
private String string1;
//更多字符串...
MyClassKey
@Embeddable
@AllArgsConstructor
@NoArgsConstructor
@Data
public class MyClassKey implements Serializable {
private static final long serialVersionUID = 1L;
private transient String string1;
private transient String string2;
private transient String string3;
@Temporal(TemporalType.TIMESTAMP)
private transient Date myDate;
}
谢谢。
英文:
I am trying to fix the vulnerabilities that Kiuwan is indicating to me.
The problem is that one of them is adding the Transient type to a Date type variable, when I do it it gives me the following error.
Caused by: org.hibernate.AnnotationException: com.pack.keys.MyClassKey has no persistent id property: com.pack.logic.MyClass.id
If i dont put transient in Date dont show the error and my project compile.
MyClass
@Table(name = "tablename")
@AllArgsConstructor
@NoArgsConstructor
@Data
public class MyClass{
@EmbeddedId
private MyClassKey id;
private String string1;
//Many String more...
MyClassKey
@Embeddable
@AllArgsConstructor
@NoArgsConstructor
@Data
public class MyClassKey implements Serializable {
private static final long serialVersionUID = 1L;
private transient String string1;
private transient String string2;
private transient String string3;
@Temporal(TemporalType.TIMESTAMP)
private transient Date myDate;
}
Thanks.
答案1
得分: 0
因为transient是Hibernate中用于排除属性的。它具有与添加@Transient
注释相同的效果:
链接:https://javaee.github.io/javaee-spec/javadocs/javax/persistence/Transient.html
英文:
Because transient is excluding attributes from Hibernate. It has the same effect as adding @Transient
annotation:
https://javaee.github.io/javaee-spec/javadocs/javax/persistence/Transient.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论