-->
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 query with condition on composite-map-key?
PostPosted: Wed Nov 14, 2007 6:00 am 
Regular
Regular

Joined: Thu Nov 13, 2003 2:55 am
Posts: 71
Location: Sweden
Hibernate version: 3.2.5

Mapping documents:
Code:
  <class name="se.exder.marketplace.suppliers.SupplierEntity" table="supplier">
    <id name="clientId" column="client_id" type="int" access="field">
      <generator class="assigned" />
    </id>
    <property name="name" column="name" type="string" />
    ...
    <map name="supplierAddresses" table="supplier_address" access="field" cascade="all-delete-orphan">
      <key column="client_id" />
      <composite-map-key class="se.exder.data.LocationCode">
        <key-property name="codelistAgencyId" column="codelist_agency_id" type="string" access="field" />
        <key-property name="locationId" column="location_id" type="string" access="field" />
      </composite-map-key>
      <element column="partner_exists" type="true_false" />
    </map>
  </class>


I need to query instances of the SupplierEntity class that has a specific key in its supplierAddresses Map. I cannot figure out how to do this with either HQL or Criteria. Currently I'm forced to use a native SQLQuery.

Here is what I have tried in HQL (only the where part differs):
1:
Code:
select distinct supplier from SupplierEntity supplier join supplier.supplierAddresses as address
where (index(address).codelistAgencyId = ? and index(address).locationId = ?)


This causes a NullPointerException at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:444).

2:
Code:
select distinct supplier from SupplierEntity supplier join supplier.supplierAddresses as address
where (address.index.codelistAgencyId = ? and address.index.locationId = ?)


This causes "cannot dereference scalar collection element"

3:
Code:
select distinct supplier from SupplierEntity supplier join supplier.supplierAddresses as address
where index(address) = ?

+ provide the composite key class (LocationCode) instance to setParameter(). This causes "SqlNode's text did not reference expected number of columns".

Any tips on how to do this in a "Hibernate fashion" are welcome.
Thanks in advance.


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.