为什么在我添加transient标签时,Hibernate会给我返回这个错误?

huangapple go评论65阅读模式
英文:

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

huangapple
  • 本文由 发表于 2020年5月5日 17:46:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/61610198.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定