Hi,
I have a table that has a nullable reference column to another table as seen in the following maps.
Code:
<hibernate-mapping>
<class catalog="..." name="RecipientGroups" table="...">
<id name="groupId" type="java.lang.Integer">
<column name="group_id"/>
<generator class="identity"/>
</id>
<property name="groupName" type="string">
<column length="45" name="group_name" not-null="true"/>
</property>
<set inverse="true" name="recipientses">
<key>
<column name="group_id"/>
</key>
<one-to-many class="Recipients"/>
</set>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class catalog="..." name=Recipients" table="...">
<id name="recipientId" type="java.lang.Integer">
<column name="recipient_id"/>
<generator class="identity"/>
</id>
<many-to-one class="RecipientGroups" fetch="select" name="recipientGroups">
<column name="group_id"/>
</many-to-one>
<property name="recipientName" type="string">
<column length="45" name="recipient_name"/>
</property>
<property name="recipientNumber" type="string">
<column length="45" name="recipient_number" not-null="true"/>
</property>
</class>
</hibernate-mapping>
group_id can be null in db design for ungrouped recipients, yet the mapping file as above.
When i run the following query within the program, i've got 0-size list but there is a record in db.
Code:
/* Some code here produces the parameters */
String name = "John Rainbow";
String number = "0033612546985";
RecipientGroups group = null;
/* Some code ...*/
List<Recipients> recipients = (List<Recipients>) session.createQuery(
"from Recipients " +
"where recipientName = :name " +
"and recipientNumber = :number " +
"and recipientGroups = :group")
.setParameter("name", name)
.setParameter("number", number)
.setParameter("group", group).list();
I ve tried the following hql on netbeans ide's HQL-Query window; it produces correct result.
Code:
from Recipients where recipientName = 'John Rainbow' and recipientNumber = '0033612546985' and recipientGroups = null;
For now, I'm not adding group parameter to the query and after checkin existence of the group in the result list in a for loop. Is something wrong on my side or is there a bug?