I post another explanation of this problem on the following page : http://www.hibernate.org/118.html
And I hope somebody will be able to help me.
And on this page use the link "I have a many-to-many association between two tables, but the association table has some extra columns (apart from the foreign keys). What kind of mapping should I use?" to see the example given by hibernate.org.
My post is at the bottom of the page.
Here is the content of my post (you can read it to have another explanation of the problem...) :
When we have many-to-many association between two tables, and the
association table has some extra columns we have to use composite
elements. But how can we handle the composite elements in a Hibernate
query ?
<set name="relationship">
<key column="fk_of_foo"/>
<composite-element class="Relationship">
<property name="multiplicity" type="short" not-null="true"/>
<property name="created" type="date" not-null="true"/>
<many-to-one name="bar" class="Bar" not-null="true"/>
</composite-element>
</set>
In this example the composite element correspond to a Java object
called Relationship (I don't speak about the set name, but about the
attribute class of the composite element).
I tried to make a query like this, but it seems that Hibernate doesn't
permit this :
SELECT o FROM Relationship AS o
But it doesn't work, Hibernate says "unexpected token: as [SELECT o
FROM Relationship AS o]
But if we suppose that we have
<class name="MyClass">
...
<set name="relationship">
<key column="fk_of_foo"/>
<composite-element class="Relationship">
<property name="multiplicity" type="short" not-null="true"/>
<property name="created" type="date" not-null="true"/>
<many-to-one name="bar" class="Bar" not-null="true"/>
</composite-element>
</set>
...
</class>
Then we can do this :
SELECT elements(o.relationship) FROM MyClass AS o
But "SELECT comp FROM MyClass AS o, Relationship AS comp WHERE comp IN
elements(o.relationship)" doesn't work still because of the class
Relationship which seems not to be recognized by Hibernate.
I really need to access Relationship object in a query in order to
make joins with some properties of the composite element.
How can I do ?
Is it possible ?
Thanks,
Nicolas