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..