Hi All,

Thanks in advance to any pointers and info. Google did not do the trick this
time around :-(

I have a DB schema design which uses "Soft/virtual Deletes" where every
table has a column "del_ind"(number) which indicates(1/0) whether a row is
considered "deleted" or not. If the app wants a row to be "deleted", it then
sets it to 1. On normal insertion, this column is set to "0".

I am using Hibernate 3 annotations(@FilterDef, @Filter) to filter out
Objects that have the "delete_ind" column set to value 1. The Filter is
working for the Main Domain Object. But the Filter is not working for the
dependent child Object(association).

Details
=======

I have a "Plan" Class that has a OneToMany relationship with "Customer"

code:
------------------------------

@Entity
@Table(name="ASSRT_PLAN")
@SequenceGenerator(name = "sequence", sequenceName = "ASSRT_PLAN_SEQ",
allocationSize = 1)
@FilterDef(name="limitPlansByDeleteStatus")

@Filter(
        name="limitPlansByDeleteStatus",
        condition="0 = ASSRT_PLAN_DEL_IND"
)
public class PlanImpl implements Plan
{
    @Column(name="ASSRT_PLAN_DEL_IND")

    private boolean deleted;


    @OneToMany(mappedBy="plan", cascade = CascadeType.ALL, fetch =
FetchType.EAGER, targetEntity=PlanCustomerImpl.class)
    @Filter(
            name="limitPlanCustomersByDeleteStatus",

            condition="0 = ASSRT_PLAN_CUST_DEL_IND"
    )
    private Set<PlanCustomer> planCustomers = new HashSet<PlanCustomer>();
.
.

} // end class PlanImpl

@Entity

@Table(name="PLAN_CUST")
@SequenceGenerator(name = "sequence", sequenceName = "PLAN_CUST_SEQ",
allocationSize = 1)
@FilterDef(name="limitPlanCustomersByDeleteStatus")
@Filter(

        name="limitPlanCustomersByDeleteStatus",
        condition="0 = ASSRT_PLAN_CUST_DEL_IND"
)
public class PlanCustomerImpl implements PlanCustomer
{
    @ManyToOne(cascade = CascadeType.ALL
, fetch = FetchType.EAGER, targetEntity = PlanImpl.class)
    @JoinColumn(name="ASSRT_PLAN_ID", nullable=false)
    private Plan plan;

    @Column(name="ASSRT_PLAN_CUST_DEL_IND")
    private Boolean deleted;

} // end class PlanCustomerImpl

/* The unit test code  */
            toDeleteCustomer.setDeleted(true);
            planDaoImpl.save(foundPlan);
            Session session = flushSession();


            /* Now, lookup the PLAN after enabling the session for "deleted"  */
            Filter filter = session.enableFilter("limitPlansByDeleteStatus");
            session.enableFilter("limitPlanCustomersByDeleteStatus");

            Plan foundAgainPlan =
planDaoImpl.getPlanByPlanNumber(TEST_PLAN_NUMBER_1);

assertFalse(foundAgainPlan.findCustomer(DELETE_NUMBER));

------------------------------



I am able to apply the Filter to the Main Entity "PlanImpl". Th filter works
just fine. But when I apply the Filter to the association of @OneToMany
association of Plan to PlanCustomer, the Filter does not work.

Does anyone know what I need to do to get it right ?

Thank you so much,

BR,
~A

Reply via email to