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]