-->
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: many-to-one multicolumn join/select with multiple columns
PostPosted: Tue Apr 04, 2006 1:31 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
I read a post about this yesterday or the day before, but I can't track it down.

I have a unidirectional many-to-one association on two columns, no primary key involved. Any time this association appears in a join or where clause, the SQL syntax is wrong: I'm getting the two relelvant columns comma separated, parenthesized, and compared to a single value. Obviously not going to work. I'm guessing that I need to implement Serializable, or create a CompositeUserType, or something, but does anyone know exactly what?

Code:
<class name="Type" ...>
  <id ...>

  <properties name="IdAndPart">
    <property name="TypeId" formula="TypeID" type="GUID"/>
    <property name="PartId" formula="StorePartitionID" type="integer"/>
  </properties>

  ...
</class>

<class name="Thing" ...>
  <id ...>

  <many-to-one name="Type" class="Type" property-ref="IdAndPart">
    <formula>AssociatedTypeID</formula>
    <formula>
      (select p.PartId from PartTable p where p.PartLabel = Label)
    </formula>
  </many-to-one>
</class>
Query:
Code:
from Thing t join t.Type ty where ty = :TypeVariable

Resulting SQL:
Code:
select thingimpl0_.ID as ID, <more stuff>
from ThingTable thingimpl0_
where (thingimpl0_.TypeID,
        (select p.PartId from PartTable p where p.PartLabel = thingimpl0_.Label))=?
I've edited this for readability, some typos may have resulted..


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.