如何在实体的 equals 方法中使用 @DiscriminatorColumn?
其实问题就在标题里。
这些实体将映射系统中不同对象的评论(博客节点、评论等) 所以我希望能够使用此专栏(读取它为特定类型的注释对象类型构建注释树的值。 另外,我想在 equals
和 hashcode
方法中添加 @DiscriminatorColumn
。
最好的方法是什么?
Actually the Question is in the title.
The entities will be map Comments for different objects in system(Blog nodes, comments, etc.)
so I want to be able work with this column(read it's value for building comment tree for particular type of Commented object type.
Also I want to add @DiscriminatorColumn
in the equals
and hashcode
methods.
What is the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
每当加载实体时,就会出现此问题,鉴别器值始终为空。因此,如果您尝试在 equals 中添加鉴别器值,您可能会得到空指针,因此有两种方法:-
insert="false" update="false"
到该属性,这将使您的属性只读,然后对于该属性,您可以放置等于。例如:-
This problem comes as whenever you load the entity, the discriminator value is always null. So if you try to add the discriminator value in equals you might get null pointer, So to do so there are two ways:-
insert="false" update="false"
on to that attribute, which will make your attribute read only, and then for that attribute you can put the equals.eg:-
DiscriminatorColumns 用于继承,A 类的实例隐式不等于 B 类,所以我不明白你为什么要这样做?
equals() 通常会执行,
DiscriminatorColumns are for inheritance, an instance of class A is implicitly not equal to a class B, so I do not understand why you would do this??
equals() would normally do a,