-->
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: Query using <map> value
PostPosted: Thu May 14, 2009 2:29 pm 
Newbie

Joined: Thu May 14, 2009 1:59 pm
Posts: 4
I have the following schema:

Code:
CREATE TABLE system (
  system_id INTEGER PRIMARY KEY,
  name TEXT NOT NULL
);

CREATE TABLE module (
  module_id INTEGER PRIMARY KEY,
  name TEXT NOT NULL
);

CREATE TABLE module_inst (
  system_id INTEGER REFERENCES system(system_id),
  module_id INTEGER REFERENCES module(module_id),
  active BOOLEAN not null
);


I am mapping the system table using the following hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="database.System" table="system" schema="test">
      <id  name="id" column="system_id"/>
      <property name="name"/>
      <property name="value"/>
      <list name="moduleInstances" inverse="true">
         <key column="system_id"/>
         <list-index column="module_id"/>
         <one-to-many class="database.ModuleInst"/>
      </list>
      <map name="moduleInstanceMap" >
         <key column="system_id"/>
         <map-key type="java.lang.String">
            <formula>(select m.name from test.module m where m.module_id = module_id)</formula>
         </map-key>
         <one-to-many class="database.ModuleInst"/>
      </map>
   </class>
</hibernate-mapping>


The moduleInstanceMap property works well (system.moduleInstanceMap['mod1'] gives me the correct thing) however, if I attempt to do a query using this map:

Code:
      q = session.createQuery("from System s where s.moduleInstanceMap[:mname] is not null and s.moduleInstanceMap[:mname].active = :active");
      q.setString("mname", "mod1");
      q.setBoolean("active",true);
      
      System.out.println(q.list());


then an exception gets thrown because the s.moduleInstanceMap[:mname] elements of the query get mapped to "system0_.system_id=moduleinst1_.system_id and moduleinst1_.null = ?" which is obviously incorrect (there is no "null" column). I would assume this is because I'm using a formula as the <map-key>. Is there a better way to do this? Am I just missing something?

Thanks for the help.
-ds


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.