-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: L2 Cache + JPA + EHCache + OneToMany Associations cr1->cr
PostPosted: Thu Aug 17, 2006 12:44 pm 
Newbie

Joined: Thu Aug 17, 2006 11:26 am
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2 cr3

Mapping documents:
Code:
@Entity
@Table(name = "SECURE_USER")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@NamedQuery(
      name="findByIdWithNonEmptyCategories",
      cacheable=true,
      cacheRegion="userCategories",
      readOnly=true,
      query=
         "from AdminUser u " +
         "left join fetch u.categoryPermissions p " +
         "left join fetch p.category cat " +
         "left join fetch cat.items item " +
         "left join fetch cat.childCategories child " +
         "left join fetch child.items item2 " +
         "where u.id = :id " +
         "and p.permissionSet.isReadable = true " +
         "and cat.parentCategory is null " +
         "and (" +
         "   (cat.childCategories is not empty) " +
         "   or " +
         "   (cat.items is not empty) " +
         ") " +
         "and child.items is not empty")
public class AdminUser extends BasePersistentObject implements Serializable {

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO, generator="SECURE_USER_ID_GEN")
   @SequenceGenerator(name="SECURE_USER_ID_GEN", sequenceName="SECURE_USER_ID")
   @Column(name = "SECURE_USER_ID")
   private Long id;

   @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
   @OneToMany(mappedBy = "adminUser", cascade=CascadeType.ALL)
   @Sort(type=SortType.NATURAL)
   private SortedSet<CategoryPermission> categoryPermissions;



Name and version of the database you are using:
Oracle9i


I'm having trouble getting L2 Cache to give me back the results of a query that returns a 'User' object containing a collection of permissions for Category objects. The Categories in turn, hold collections of other Categories and Items.

When I run this query without query caching enabled, it works just fine (but slower than I want).
When I run it with Hibernate cr1 with query cache turned on, it only returns the top-level Categories (embedded in the Permissions/User) and I get an error in logs saying that the embedded Items can't be lazily loaded.
When I run it with Hibernate cr3, I get the error:

Quote:
object references an unsaved transient instance - save the transient instance before flushing: model.CategoryPermission.category -> model.Category


As you'll see in the code listing for the AdminUser class, I have annotated the collection of CategoryPermissions to be cached. Likewise, I've annotated CategoryPermission's association (ManyToOne) to a Category, to be cached too, and so on (Category -> childCategories, Category -> Items).

I'm using EHCache and I've tried with & without specifying in the ehcache config file, various settings for all the cached entities and their associations.

Ideas?

Thanks,
Terry[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.