简体   繁体   English

如何使用注释继承Hibernate过滤器?

[英]How can I inherit Hibernate filters with annotations?

I'm trying to set up a Hibernate filter with annotations. 我正在尝试使用注释设置Hibernate过滤器。 I would like to specify it in a base class and make all sub classes use it but whenever I try to enable it, Hibernate fails to find the filter. 我想在基类中指定它并使所有子类使用它但是每当我尝试启用它时,Hibernate都无法找到过滤器。 Is it possible at all to inherit filter annotations? 是否有可能继承过滤器注释?

Since 3.5.0 it's at least possible for @MappedSuperclass. 从3.5.0开始,@MappedSuperclass至少可以实现。 Not sure if that helps you... see: HHH-4332 不确定这有助于你......见: HHH-4332

Are you using the hibernate filter directly, or are you extending the hibernate filter for your own purposes? 您是直接使用休眠过滤器,还是为了自己的目的扩展休眠过滤器? Annotations aren't inherited by default in Java, although if you were writing the annotation yourself, and I'm assuming hibernate didn't do this on their annotations, you can specify the @Inherited meta-annotation on your annotation to make it inherit. Java中没有默认继承注释,但如果您自己编写注释,并且我假设hibernate没有在注释上执行此操作,则可以在注释上指定@Inherited元注释以使其继承。 This only works for Type level annotations, though. 但这仅适用于类型级别注释。 Also, some people write an annotation manager to simulate full inheritance. 此外, 有些人编写注释管理器来模拟完全继承。 You could do something like that, either extend hibernates mechanism or write a preprocessor that adds the annotations where they should have been inherited. 您可以执行类似的操作,或者扩展休眠机制,或者编写一个预处理器来添加应该继承的注释。

What John Ellinwood wrote is precisely the case. John Ellinwood写的正是如此。 That is why @Filter needs to be specified on all subclasses, at least in Hibernate Annotations 3.4.0-GA. 这就是为什么需要在所有子类上指定@Filter原因,至少在Hibernate Annotations 3.4.0-GA中是这样。

Furthermore, although that might not be apparent, you will need the same annotation on all mapped collections of that class, if you expect those collections to be susceptible to filtering as well. 此外,虽然这可能并不明显,但如果您希望这些集合也易于过滤,那么您将需要在该类的所有映射集合上使用相同的注释。

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

相关问题 我可以简化 Hibernate 注释吗? - Can I simplify Hibernate annotations? 如何在运行时更改注释/ Hibernate验证规则? - How can I change annotations/Hibernate validation rules at runtime? 如何使用Hibernate注释标记外键约束? - How can I mark a foreign key constraint using Hibernate annotations? Hibernate:如何创建已保存的过滤器然后使用它们? - Hibernate: How can I create saved filters and then use them? 如何使用 Hibernate 注释创建允许 NULL 值的唯一约束? - How can I create a Unique Constraint that allows NULL values with Hibernate annotations? 如何使用Hibernate注释将Java日期映射到mysql中的DATETIME(默认情况下为TIMESTAMP) - How can I map a Java date to DATETIME in mysql (by default its TIMESTAMP) with Hibernate annotations 如何在不更改注释的情况下禁用Hibernate中某些特定实体的二级缓存 - How I can disable the second-level cache of some certain entities in Hibernate without changing annotations 如何自定义使用Hibernate的hbm2ddl生成的DDL(使用批注)? - How can I customize the DDL generated with Hibernate's hbm2ddl (using annotations)? 如何使用休眠注释 - How to use Hibernate annotations 我可以在bean验证中使用休眠实体注释吗 - Can I use hibernate entity annotations with bean validation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM