views:

10

answers:

0

I have Category class containing list of products. Like this:

public class Category{
 ...
 @0neToMany
 @JoinColumn("category_id") 
 List<Product> products;
 public List<Product> getProducts();
 ... 
}

When I call getProducts() I want to lock returned collection so that other transaction could not modify it while current one isn't commited. I know it is possible to lock objects returned by the query calling

 getSession().createQuery("from Product p where category_id =:cat_id")
                .setParameter("cat_id", 1)
                .setLockMode("c", LockMode.UPGRADE)
                .list();

for example. Is it possible to lock collection of products returned by getter method?