简体   繁体   English

为什么 hibernate 在我放置 transient 标签时会给我这个错误?

[英]Why does hibernate give me this error when I put the transient tag?

I am trying to fix the vulnerabilities that Kiuwan is indicating to me.我正在尝试修复 Kiuwan 向我指出的漏洞。

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.问题是其中之一是将 Transient 类型添加到 Date 类型变量,当我这样做时它会给我以下错误。

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.谢谢。

Because transient is excluding attributes from Hibernate. It has the same effect as adding @Transient annotation:因为transient排除了Hibernate中的属性,和添加@Transient注解效果一样:

https://javaee.github.io/javaee-spec/javadocs/javax/persistence/Transient.html https://javaee.github.io/javaee-spec/javadocs/javax/persistence/Transient.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我给一个瞬态变量一个列标签,在冬眠会发生什么? - what happens in hibernate if i give a column tag for a transient variable? 如果我输入一个未在数组中定义的值,为什么二进制搜索方法会给我一个错误? - Why does the binary search method give me an error if i put in a value that is not defined in the array? 为什么即使我声明了 rand,它也会给我一个错误? - Why does it give me an error even though I declared rand? 为什么 i = i + i 给我 0? - Why does i = i + i give me 0? Hibernate给我一个错误,因为对象引用了一个未保存的临时实例-但我希望它在数据库中保持未保存状态 - Hibernate gives me an error because an object references an unsaved transient instance - but I want it to remain unsaved in the DB 为什么命令提示符在编译时给我一个错误代码,而我的 IDE 却没有? - Why does command prompt give me an error code in compilation when my IDE doesn't? 如果多次调用此方法,为什么有时会给我一个错误 - Why does this method sometimes give me an error if I call it more than once 当我尝试运行示例应用程序时,为什么eclipse给我错误? - Why does eclipse give me errors when i try to run sample application? 为什么它给我 BufferUnderflowException - Why does it give me BufferUnderflowException 为什么声明一个新对象会给我一个语法错误? - Why does declaring a new object give me a syntax error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM