-->
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: How To Fetch Associated Entities Mapped With Any Element
PostPosted: Thu Aug 02, 2007 1:49 pm 
Newbie

Joined: Tue Apr 25, 2006 4:04 pm
Posts: 4
Having avoided the use of the <any> mapping, I find myself using it now for an Audit implementation. However, I'm not sure how to load the associated entities mapped with <any> using Hibernate 3.2 with XML mapping files.

Suppose the Audit class has an auditedEntity attribute mapped with an <any> element:

Code:
  <any name="auditedEntity" id-type="long" meta-type="string">
      <meta-value value="ENTITY_A" class="EntityA" />
      <meta-value value="ENTITY_B" class="EntityB" />
      <meta-value value="ENTITY_C" class="EntityC" />
      <meta-value value="ENTITY_Z" class="EntityZ" />
      <column name="ENTITY_TYPE" />
      <column name="ENTITY_ID" />
  </any>


The EntityX classes don't have a mapped attribute to the Audit class because no foreign key relationship can exist from these to the Audit table.

Now, I want to load only those audit records pertaining to EntityA, where the endtityA.id = ?.

I'm just not sure what the query should look like. I've tried a Criteria query against Audit where I do a join to the auditedEntity, like this:
Code:
  List list = session.createCriteria(Audit.class)
           .setFetchMode("auditedEntity", FetchMode.JOIN)
          .add( Restrictions.like("id", id))
      .list();


but I get an UnsupportedOperationException with the message, "any types do not have a unique referenced persister"

Clearly, I'm missing something important about using the <any> mapping.

TIA.

_________________
--
jj


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.