-->
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: SQL to HQL query with bags and any
PostPosted: Thu Jan 06, 2005 4:58 pm 
Beginner
Beginner

Joined: Mon Dec 29, 2003 12:49 pm
Posts: 41
Location: Boston, MA
Hello all,

I'm trying to convert the following SQL query to HQL and am not sure if it is totally possible:

Code:
select * from PARTY as p
left join object_association as oa
on p.party_id = oa.associated_object_id
left join  party as p1
on oa.master_object_id = p1.party_id
where p.name_human_first = 'Brian' and
p1.organization_name = 'RTE';


Party is a table that hold instances of both Humans and Organizations discriminated by an object_type_id. An instance of Human is "associated" with an Organization through a table called object_associations which represents a many-to-many between instances of Party. It is mapped as a "bag" in the mapping file from 2 perspectives - what the parent object is and what the child object is. Any two object types in the system may be "related" through this table, hence each object has a set of "associations" which represents those objects of which it is a child and a set of "associatedObject" which represents those objects for which it is the parent. Each of these sets contain instances of ObjectAssociation, which in turn has a "master object" and "associated object." In the case of Human -> Organization, the Organization is the master object and the Human is the associated object. A row then exists in object_association with a master_object_id = to the party_id of the Organization and an associated_obejct_id = to the party_id of the Human. Also, each instance of an ObjectAssociation has an object_type_id which relates to an type_object table - it is essentially a way of saying what the nature of the relationship is between 2 objects (e.g. "Employed By"). I want to be able to find, for example, all the Humans whose first name = "Brian" that are associated with an Organiztion whose name = "RTE" (and also with an object_type.typeName = "Employed By". The SQL query works as expeccted - it returns a unique result. The HQL I've come up with has become more difficult however as it returns a Cartesian Product of all people named "Brian" along with an instance of the Organization whose name is "RTE"

Code:
from org.wgbh.scape.domain.Human as p,
org.wgbh.scape.domain.Organization as p1
left join p.associations
left join p1.associatedObjects
where p.firstName = 'Brian' and
p1.name = 'RTE';


The problem, of course, is the "any" mapping between an ObjectAssociation instance and its other objects. They can represent any object in the system so at any given moment, the master_object could be Human, Organization or Fruity Pebbles and so could the associatedObject. I can mitigate this in the interface because I know what is being searched for from a particular search page (for exmaple, there is a specific human search page with a field for Company Name and First Name). But I'm not sure how Hibernate handles the relationship between bags and any and if they are searchable in this way. I've also tried the Criteria API using the following:

Code:
         Example exampleAssociation = Example.create( query.getAssociation() ).ignoreCase();//.enableLike( MatchMode.ANYWHERE );
         Example exampleObject = query.fromMaster()
            ? Example.create( query.getMasterObject() ).ignoreCase().enableLike( MatchMode.ANYWHERE )
            : Example.create( query.getAssociatedObject() ).ignoreCase().enableLike( MatchMode.ANYWHERE );
         
         Criteria crit = session.createCriteria( query.getQueryClass() ).add( exampleObject ).createCriteria( query.fromMaster() ? "associatedObjects" : "associations" ).add( exampleAssociation );
         logger.debug( "Criteria class = " + crit.getCriteriaClass() );
         
         return new UFOSet( crit.list() );


The API use generates the following SQL:

Code:
Hibernate: select objecttype0_.object_type_id as object_t1_0_, objecttype0_.object_type_parent_id as object_t2_0_, objecttype0_.object_type as object_t3_0_, objecttype0_.description as descript4_0_ from type_object objecttype0_ where objecttype0_.object_type_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
Hibernate: select objecttype0_.object_type_id as object_t1_0_, objecttype0_.object_type_parent_id as object_t2_0_, objecttype0_.object_type as object_t3_0_, objecttype0_.description as descript4_0_ from type_object objecttype0_ where objecttype0_.object_type_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
Hibernate: select objecttype0_.object_type_id as object_t1_0_, objecttype0_.object_type_parent_id as object_t2_0_, objecttype0_.object_type as object_t3_0_, objecttype0_.description as descript4_0_ from type_object objecttype0_ where objecttype0_.object_type_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
Hibernate: select objecttype0_.object_type_id as object_t1_0_, objecttype0_.object_type_parent_id as object_t2_0_, objecttype0_.object_type as object_t3_0_, objecttype0_.description as descript4_0_ from type_object objecttype0_ where objecttype0_.object_type_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
Hibernate: select objecttype0_.object_type_id as object_t1_0_, objecttype0_.object_type_parent_id as object_t2_0_, objecttype0_.object_type as object_t3_0_, objecttype0_.description as descript4_0_ from type_object objecttype0_ where objecttype0_.object_type_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
Hibernate: select objecttype0_.object_type_id as object_t1_0_, objecttype0_.object_type_parent_id as object_t2_0_, objecttype0_.object_type as object_t3_0_, objecttype0_.description as descript4_0_ from type_object objecttype0_ where objecttype0_.object_type_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
Hibernate: select organizati0_.party_id as party_id0_, organizati0_.ein as ein0_, organizati0_.organization_name as organiz19_0_, organizati0_.description as descrip10_0_, organizati0_.object_type_id as object_t2_0_, organizati0_.note as note0_ from party organizati0_ where organizati0_.party_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
Hibernate: select phonelist0_.party_id as party_id__, phonelist0_.phone_id as phone_id__, phonelist0_.phone_id as phone_id0_, phonelist0_.object_type_id as object_t2_0_, phonelist0_.party_id as party_id0_, phonelist0_.phone_country_code as phone_co4_0_, phonelist0_.phone_area_code as phone_ar5_0_, phonelist0_.phone_number as phone_nu6_0_, phonelist0_.phone_extension as phone_ex7_0_ from phone phonelist0_ where phonelist0_.party_id=?
Hibernate: select emaillist0_.party_id as party_id__, emaillist0_.email_id as email_id__, emaillist0_.email_id as email_id0_, emaillist0_.object_type_id as object_t2_0_, emaillist0_.party_id as party_id0_, emaillist0_.email as email0_ from email emaillist0_ where emaillist0_.party_id=?
Hibernate: select addresslis0_.party_id as party_id__, addresslis0_.address_id as address_id__, addresslis0_.address_id as address_id0_, addresslis0_.object_type_id as object_t2_0_, addresslis0_.party_id as party_id0_, addresslis0_.state as state0_, addresslis0_.country as country0_, addresslis0_.address_1 as address_10_, addresslis0_.address_2 as address_20_, addresslis0_.address_3 as address_30_, addresslis0_.city as city0_, addresslis0_.province as province0_, addresslis0_.zip as zip0_, addresslis0_.zip_4 as zip_40_ from address addresslis0_ where addresslis0_.party_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
15:49:14,986 [http8080-Processor1] DEBUG org.wgbh.scape.ScapeFilter.reassociateWithSession:   65 - session already contains object: CNTC1582
Hibernate: select organizati0_.party_id as party_id0_, organizati0_.ein as ein0_, organizati0_.organization_name as organiz19_0_, organizati0_.description as descrip10_0_, organizati0_.object_type_id as object_t2_0_, organizati0_.note as note0_ from party organizati0_ where organizati0_.party_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
Hibernate: select phonelist0_.party_id as party_id__, phonelist0_.phone_id as phone_id__, phonelist0_.phone_id as phone_id0_, phonelist0_.object_type_id as object_t2_0_, phonelist0_.party_id as party_id0_, phonelist0_.phone_country_code as phone_co4_0_, phonelist0_.phone_area_code as phone_ar5_0_, phonelist0_.phone_number as phone_nu6_0_, phonelist0_.phone_extension as phone_ex7_0_ from phone phonelist0_ where phonelist0_.party_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
Hibernate: select emaillist0_.party_id as party_id__, emaillist0_.email_id as email_id__, emaillist0_.email_id as email_id0_, emaillist0_.object_type_id as object_t2_0_, emaillist0_.party_id as party_id0_, emaillist0_.email as email0_ from email emaillist0_ where emaillist0_.party_id=?
Hibernate: select addresslis0_.party_id as party_id__, addresslis0_.address_id as address_id__, addresslis0_.address_id as address_id0_, addresslis0_.object_type_id as object_t2_0_, addresslis0_.party_id as party_id0_, addresslis0_.state as state0_, addresslis0_.country as country0_, addresslis0_.address_1 as address_10_, addresslis0_.address_2 as address_20_, addresslis0_.address_3 as address_30_, addresslis0_.city as city0_, addresslis0_.province as province0_, addresslis0_.zip as zip0_, addresslis0_.zip_4 as zip_40_ from address addresslis0_ where addresslis0_.party_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
15:49:15,081 [http8080-Processor1] DEBUG org.wgbh.scape.ScapeFilter.reassociateWithSession:   65 - session already contains object: CNTC408
Hibernate: select organizati0_.party_id as party_id0_, organizati0_.ein as ein0_, organizati0_.organization_name as organiz19_0_, organizati0_.description as descrip10_0_, organizati0_.object_type_id as object_t2_0_, organizati0_.note as note0_ from party organizati0_ where organizati0_.party_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
Hibernate: select phonelist0_.party_id as party_id__, phonelist0_.phone_id as phone_id__, phonelist0_.phone_id as phone_id0_, phonelist0_.object_type_id as object_t2_0_, phonelist0_.party_id as party_id0_, phonelist0_.phone_country_code as phone_co4_0_, phonelist0_.phone_area_code as phone_ar5_0_, phonelist0_.phone_number as phone_nu6_0_, phonelist0_.phone_extension as phone_ex7_0_ from phone phonelist0_ where phonelist0_.party_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?
Hibernate: select emaillist0_.party_id as party_id__, emaillist0_.email_id as email_id__, emaillist0_.email_id as email_id0_, emaillist0_.object_type_id as object_t2_0_, emaillist0_.party_id as party_id0_, emaillist0_.email as email0_ from email emaillist0_ where emaillist0_.party_id=?
Hibernate: select addresslis0_.party_id as party_id__, addresslis0_.address_id as address_id__, addresslis0_.address_id as address_id0_, addresslis0_.object_type_id as object_t2_0_, addresslis0_.party_id as party_id0_, addresslis0_.state as state0_, addresslis0_.country as country0_, addresslis0_.address_1 as address_10_, addresslis0_.address_2 as address_20_, addresslis0_.address_3 as address_30_, addresslis0_.city as city0_, addresslis0_.province as province0_, addresslis0_.zip as zip0_, addresslis0_.zip_4 as zip_40_ from address addresslis0_ where addresslis0_.party_id=?
Hibernate: select associated0_.master_object_id as master_o4___, associated0_.object_association_id as object_a1___, associated0_.object_association_id as object_a1_0_, associated0_.object_type_id as object_t2_0_, associated0_.master_object_class as master_o3_0_, associated0_.master_object_id as master_o4_0_, associated0_.associated_object_class as associat5_0_, associated0_.associated_object_id as associat6_0_ from object_association associated0_ where associated0_.master_object_id=?
Hibernate: select associatio0_.associated_object_id as associat6___, associatio0_.object_association_id as object_a1___, associatio0_.object_association_id as object_a1_0_, associatio0_.object_type_id as object_t2_0_, associatio0_.master_object_class as master_o3_0_, associatio0_.master_object_id as master_o4_0_, associatio0_.associated_object_class as associat5_0_, associatio0_.associated_object_id as associat6_0_ from object_association associatio0_ where associatio0_.associated_object_id=?


Hope this makes sense.. thanks for sticking with the post to the end and thanks for any ideas, assistance or suggestions (even those of the "Why the @!#$ are you doing it this way?" type. I'm beginning to think I may need to make some significant changes.)

--Brian

Hibernate version: 2.1.7

Mapping documents:

Code:

   <class name="org.wgbh.scape.domain.PartyImpl" table="party" polymorphism="implicit" proxy="org.wgbh.scape.domain.PartyImpl">
      <meta attribute="class-description"> @author Brian R. Wainwright @version 1.0 </meta>
      <meta attribute="implements">org.wgbh.scape.domain.Party</meta>
      <meta attribute="implements">org.wgbh.scape.domain.ScapeObject</meta>
      <id column="party_id" name="partyID" type="string" unsaved-value="null">
         <generator class="uuid.hex"/>
      </id>
      
      <discriminator column="object_type_id" type="string"/>
      
      <!--<one-to-one name="ufo" class="org.wgbh.scape.domain.UnidentifiedFoundationObjectImpl"/>-->
      <many-to-one class="org.wgbh.scape.domain.ObjectTypeImpl" column="object_type_id"
         name="objectType" insert="false" update="false"/>
      <bag name="associatedObjects" batch-size="100" lazy="true" outer-join="false" cascade="all">
         <key column="master_object_id"/>
         <one-to-many class="org.wgbh.scape.domain.ObjectAssociationImpl"/>
      </bag>
      <bag name="associations" batch-size="100" lazy="true" outer-join="false" cascade="all">
         <key column="associated_object_id"/>
         <one-to-many class="org.wgbh.scape.domain.ObjectAssociationImpl"/>
      </bag>
      <subclass name="org.wgbh.scape.domain.HumanImpl" discriminator-value="OT4" proxy="org.wgbh.scape.domain.HumanImpl" >
         <meta attribute="class-description"> @author Brian R. Wainwright @version
            1.0 </meta>
         <meta attribute="implements">org.wgbh.scape.domain.Human</meta>
         <property column="ssn" insert="true" name="socialSecurityNumber"
            type="string" update="true">
            <meta attribute="finder">findBySSNumber</meta>
         </property>
         <property column="name_human_first" insert="true" name="firstName"
            type="string" update="true">
            <meta attribute="finder">findByFirstName</meta>
         </property>
         <property column="name_human_middle" insert="true" name="middleName"
            type="string" update="true">
            <meta attribute="finder">findByMiddleName</meta>
         </property>
         <property column="name_human_last" insert="true" name="lastName"
            type="string" update="true">
            <meta attribute="field-description">The last name of the person.</meta>
            <meta attribute="finder">findByLastName</meta>
         </property>
         <property column="name_human_prefix" insert="true" name="namePrefix"
            type="string" update="true"/>
         <property column="name_human_suffix" insert="true" name="nameSuffix"
            type="string" update="true"/>
         <property column="description" insert="true" name="description"
            type="string" update="true"/>
         <property column="job_title" insert="true" name="title" type="string" update="true"/>
         <!-- property column="holiday_card" insert="true" name="holidayCard"
            type="string" update="true"/ -->
         <subclass name="org.wgbh.scape.domain.UserImpl" discriminator-value="OT7" proxy="org.wgbh.scape.domain.UserImpl">
            <meta attribute="class-description"> A Users object represents a
               user of the application identified by a username and a
               password. @author Brian R. Wainwright @version 1.0 </meta>
            <meta attribute="implements">org.wgbh.scape.domain.User</meta>
            <property column="username" insert="true" name="username"
               type="string" update="true">
               <meta attribute="finder">findByUsername</meta>
            </property>
            <property column="password" insert="true" name="password"
               type="string" update="true">
               <meta attribute="finder">findByPassword</meta>
            </property>
            <property column="password_expires" insert="true"
               name="passwordExpires" type="date" update="true"/>
            <property column="password_retention" insert="true"
               name="passwordRetention" type="integer" update="true"/>
            <property column="password_hint" insert="true" name="passwordHint"
               type="string" update="true"/>
            <property column="password_answer" insert="true"
               name="passwordAnswer" type="string" update="true">
               <meta attribute="finder">findByPwdAnswer</meta>
            </property>
         </subclass>
      </subclass>
      <subclass name="org.wgbh.scape.domain.OrganizationImpl" discriminator-value="OT39" proxy="org.wgbh.scape.domain.OrganizationImpl">
         <meta attribute="class-description">
            @author Brian R. Wainwright @version
            1.0
         </meta>
         <meta attribute="implements">org.wgbh.scape.domain.Organization</meta>
         <property column="ein" insert="true" name="employerIDNumber" type="string" update="true">
            <meta attribute="finder">findByEIN</meta>
         </property>
         <property column="organization_name" insert="true" name="name" type="string" update="true">
            <meta attribute="finder">findByName</meta>
         </property>
         <property column="description" insert="true" name="description"
            type="string" update="true"/>
      </subclass>
      <subclass name="org.wgbh.scape.domain.GroupImpl" discriminator-value="OT6" proxy="org.wgbh.scape.domain.GroupImpl">
         <meta attribute="class-description"> @author Brian R. Wainwright @version
            1.0 </meta>
         <meta attribute="implements">org.wgbh.scape.domain.Group</meta>
         <property column="group_name" insert="true" name="name" type="string" update="true">
            <meta attribute="finder">findByName</meta>
         </property>
         <property column="description" insert="true" name="description" type="text" update="true"/>
      </subclass>      
   </class>
   
   <class name="org.wgbh.scape.domain.ObjectAssociationImpl" table="object_association" polymorphism="implicit" proxy="org.wgbh.scape.domain.ObjectAssociationImpl">
      <meta attribute="class-description"> @author Brian R. Wainwright @version 1.0 </meta>
      <meta attribute="implements">org.wgbh.scape.domain.ObjectAssociation</meta>
      <meta attribute="implements">org.wgbh.scape.domain.ScapeObject</meta>
      <id column="object_association_id" name="objectAssociationID" type="string" unsaved-value="null">
         <generator class="uuid.hex"/>
      </id>
      <!--<one-to-one name="ufo" class="org.wgbh.scape.domain.UnidentifiedFoundationObjectImpl"/>-->
      <many-to-one class="org.wgbh.scape.domain.ObjectTypeImpl" column="object_type_id" name="objectType"/>
      
      <any id-type="string" name="masterObject">
         <column name="master_object_class"/>
         <column name="master_object_id"/>
      </any>
      
      <any id-type="string" name="associatedObject">
         <column name="associated_object_class"/>
         <column name="associated_object_id"/>
      </any>
      
   </class>
   
   <class name="org.wgbh.scape.domain.ObjectTypeImpl" table="type_object" polymorphism="implicit" proxy="org.wgbh.scape.domain.ObjectTypeImpl">
      <meta attribute="class-description"> @author Brian R. Wainwright @version 1.0 </meta>
      <meta attribute="implements">org.wgbh.scape.domain.ScapeType</meta>
      <meta attribute="implements">org.wgbh.scape.domain.ObjectType</meta>
      <meta attribute="implements">org.wgbh.scape.domain.ScapeObject</meta>
      <id column="object_type_id" name="objectTypeID" type="string" unsaved-value="null">
         <generator class="uuid.hex"/>
      </id>
      <!--<one-to-one name="ufo" class="org.wgbh.scape.domain.UnidentifiedFoundationObjectImpl"/>-->
      <many-to-one class="org.wgbh.scape.domain.ObjectTypeImpl"
         column="object_type_parent_id" name="parentObject" />
      <property column="object_type" name="typeName" type="string">
         <meta attribute="finder">findByTypeName</meta>
      </property>
      <property column="description" name="description" type="text"/>
      <set batch-size="20" inverse="true" name="childObjects" outer-join="false" lazy="true">
         <key column="object_type_id"/>
         <one-to-many class="org.wgbh.scape.domain.ObjectTypeImpl"/>
      </set>
      <bag name="associatedObjects" batch-size="100" lazy="true" outer-join="false"  cascade="all">
         <key column="master_object_id"/>
         <one-to-many class="org.wgbh.scape.domain.ObjectAssociationImpl"/>
      </bag>
      <bag name="associations" batch-size="100" lazy="true" outer-join="false" cascade="all">
         <key column="associated_object_id"/>
         <one-to-many class="org.wgbh.scape.domain.ObjectAssociationImpl"/>
      </bag>
      
   </class>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using: MySQL 4.1.17

The generated SQL (show_sql=true): see above

Debug level Hibernate log excerpt:

_________________
Brian R. Wainwright
Systems Developer
WGBH Educational Foundation

"WGBH Boston informs, inspires, and entertains millions through public broadcasting, the Web, and educational multimedia, and access services for people with disabilities."


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.