Hi everybody,
As you will probably guess, I am new to Hibernate... Shame on me.
I have a question concerning HQL.
I need to do a query to my database but can't succeed in HQL. It works fine in SQL.
The 'simplified' context is:
I have 2 tables:
- Collections
- Collections_Content
One 'Collections' can have between 1 and X 'Collections_Content'.
Here is the 'Collections' mapping file:
Code:
<hibernate-mapping>
<class name="Collections" table="COLLECTIONS">
<id name="coll_id" column="c_uid" type="long">
<generator class="increment"/>
</id>
<property name="identifier" type="string"/>
<property name="searchable" type="boolean"/>
<property name="harvestable" type="boolean"/>
<property name="theme" type="string"/>
<property name="publisher" type="string"/>
<property name="country" type="string"/>
<property name="thumbnail" type="string"/>
<property name="belongs_to" type="string" />
<property name="type" type="string" />
<bag name="collectionsSearch" inverse="true" order-by="DATE_TIME" cascade="all">
<key column="c_uid" />
<one-to-many class="CollectionsSearch" />
</bag>
</class>
</hibernate-mapping>
And here the Collections_Content mapping file:
Code:
<hibernate-mapping>
<class name="CollectionsContent" table="COLLECTIONS_CONTENT">
<id name="cc_uid" column="cc_uid" type="long">
<generator class="increment"/>
</id>
<many-to-one name="collections" column="c_uid" not-null="true" class="Collections" />
<property name="language" type="string"/>
<property name="title" type="string"/>
<property name="description" type="string"/>
</class>
</hibernate-mapping>
I want to retrieve information from both table, but just ONE ROW per Collections.coll_id.
Why ? Because I want to retrieve one 'Collections' with its 'Collections_Content' information in a SPECIFIC language, and if this SPECIFIC language doesn't exist, I need to switch it to English.
And not 6 rows of the same Collections.coll_id with different languages/title/description.
For the moment, I can, of course, access both tables, in a specific language using something like:
Code:
getHibernateTemplate().find("from Collections c" +
" left join c.collectionsContent cc" +
" WITH (cc.language='" + language + "')");
where language can be 'en', 'de', 'nl', ...
But sometimes, those languages don't exist for that specific 'Collections', and then I would need to get the row anyway but with language switched to English.
I have no idea how to make this possible in Hibernate...
Could you please help me on this one ?
Thanks a lot,
Yoann