天道酬勤,学无止境

hibernate-filters

Hibernate enableFilter not working when loading entity by id

I have 3 classes: Event PublicEvent extends Event PersonalEvent extends Event my hibernate mapping file is somethings like bellow. i wanna add one filter for PersonalEvent and before loading this object, i was enabled that's filter. but this is not working. my hibernate version is 4.3.11.Final. Event.hbm.xml <hibernate-mapping> <class name="org.calendar.Event"> ... <filter name="personalEventAuthorize" condition="person_ID = :personId" /> </class> <joined-subclass name="org.calendar.PersonalEvent" extends="org.calendar.Event"> <key column="id" property-ref="id" /> ... <many-to-one name="person

2021-11-25 03:56:01    分类:问答    java   hibernate   orm   nhibernate-mapping   hibernate-filters

How to add a where clause to a Hibernate @OneToMany explicit join table entity?

Given two entities: Card PurchaseProductGroup, which has a ppg_status column (field named as status on the entity) that can be 'A' (active) or 'D' (deleted) These conceptually have a many-to-many relationship but an explicitly defined join table entity named PurchaseProductGroupCard is used (so an external ID can be assigned for each mapping). So both Card and PurchaseProductGroup have a @OneToMany relationship to PurchaseProductGroupCard, e.g. in Card there is the following: @OneToMany(mappedBy = "card") private Set<PurchaseProductGroupCard> purchaseProductGroups; This needs to be restricted

2021-11-07 08:30:36    分类:问答    oracle   hibernate   many-to-many   jointable   hibernate-filters

休眠过滤器不适用于加入实体(Hibernate filter does not apply for join entity)

问题 我正在尝试了解休眠过滤器,我认为即使查询不是从过滤的实体开始,也会应用过滤器,并且如果我只是加入它就可以应用。 我的实体: @Table(name = "SPM_SECTION", schema = "TEST") @GenericGenerator(name = "MODSEC_ID.GEN", strategy = "uuid2") public class ModuleSection implements Serializable { private AcademicClass academicClass; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "CLASS_ID") public AcademicClass getAcademicClass() { return academicClass; } public void setAcademicClass(AcademicClass academicClass) { this.academicClass = academicClass; } } @Entity @GenericGenerator(name = "AC_CLASS_ID.GEN", strategy = "uuid2") @Where(clause="1=1") @FilterDef

2021-10-30 13:11:47    分类:技术分享    java   hibernate   java-ee-8   hibernate-filters

Hibernate filter does not apply for join entity

I am trying to understand hibernate filters, i thought that the filter is applied even if the query is not started from the filtered entity and can be applied if i just join to it. My entities: @Table(name = "SPM_SECTION", schema = "TEST") @GenericGenerator(name = "MODSEC_ID.GEN", strategy = "uuid2") public class ModuleSection implements Serializable { private AcademicClass academicClass; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "CLASS_ID") public AcademicClass getAcademicClass() { return academicClass; } public void setAcademicClass(AcademicClass academicClass) { this

2021-09-02 03:31:28    分类:问答    java   hibernate   java-ee-8   hibernate-filters

Soft delete an entity in Grails with Hibernate Filters Plugin

I was looking for a way to avoid deleting my users from DB, but instead to mark them as deleted and don't bring them back in queries. I found this plugin http://grails.org/plugin/hibernate-filter, which was a great tool for the task. But when I tried to implement my solution, I passed trought same problems whose solutions wheren't (or I was not able to find) on internet. So, next, I describe the way that I solve the problem of soft delete.

2021-08-11 21:10:36    分类:问答    grails   grails-orm   soft-delete   hibernate-filters

Spring , Transactions , Hibernate Filters

I am using declarative transactions in Spring. I have a service layer which is annotated with "Transactional". This service layer calls the DAO. I need to enable a hibernate filter in all the dao methods. I don't want to have to explicitly call teh session.enablefilter each time. So is there a way using spring transaction aop etc such that a intercepter can be called when the hibernate session is created? My Service layer: @Service("customerViewService") @Transactional public class CustomerViewServiceImpl extends UFActiveSession implements CustomerViewService { private static final Logger log

2021-08-11 07:14:56    分类:问答    spring   transactional   hibernate-filters

将动态参数传递给注释(Passing dynamic parameters to an annotation)

问题 我想知道是否有可能将值动态传递给注释属性。 我知道注解并非旨在进行修改,但我使用的是Hibernate过滤器,在我的情况下,放置的条件不是静态的。 我认为唯一的解决方案是使用librairies,其目的是读取和修改Javassist或ASM之类的字节码,但是如果有其他解决方案,那就更好了。 ps:我遇到的困难是我应该修改注释(属性的值),但是我上面提到的库允许创建不编辑,这就是为什么我想知道其他解决方案的原因 提前致谢 回答1 我不知道它是否与您的框架很好地集成在一起,但是我想提出以下建议: 创建一个注释,该注释接收实现验证规则的类创建一个注释可以接收的接口为具有规则逻辑的接口创建一个实现将注释添加到模型类创建一个注释处理器,对每个带注释的字段应用验证 我用Groovy编写了以下示例,但是使用了标准Java库和惯用Java。 如果有任何不可读的地方,请警告我: import java.lang.annotation.* // Our Rule interface interface Rule<T> { boolean isValid(T t) } // Here is the annotation which can receive a Rule class @Retention(RetentionPolicy.RUNTIME) @interface Validation {

2021-05-18 13:31:49    分类:技术分享    java   annotations   bytecode   javassist   hibernate-filters

Passing dynamic parameters to an annotation

I wonder if there is a possiblity to pass dynamically values to an annotation attribute. I know that annotation are not designed to be modified but I'm using Hibernate Filters and condition to be put are not static in my case. I think that the only solution is to use librairies whose aim is to read and modify byte code such as Javassist or ASM but it would be too much better if there is another solution. ps: The difficulty in my case is that I should modify annotations (attribute's value) but librairies I mentioned above allow to create not to edit that's why I'm wondering for another solution

2021-04-30 21:30:52    分类:问答    java   annotations   bytecode   javassist   hibernate-filters

How to enable hibernate filter for sessionFactory.getCurrentSession()?

Say there is a User table with structure: User List item userId (PK) company (PK) userName address ...etc And I want to retrieve users only for the current company (company can be changed by the user through UI, so the company is a runtime parameter) Similarly there are many other tables that have similar structure with common column (company), and I want to restrict data to only the current company, so I am using hibernate filter to filter out data. Hibernate annotations: <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property

2021-04-08 18:55:38    分类:问答    hibernate   spring   hibernate-annotations   hibernate-filters