Hi:
I am having troubles (and a horrible headache) with several associations in my code.
My system
Hibernate version: 3.3
MySQL 5/ Oracle 10i
The associations are all "many-to-one" and defined like this:
Code:
<class name="Tmaster" table="tmaster">
<id name="id" type="long" column="TMASTER_ID" >
<generator class="assigned"/>
</id>
<property name="name">
<column name="TMASTER_NAME" />
</property>
<property name="lastName">
<column name="TMASTER_LASTNAME"/>
</property>
<property name="email">
<column name="TMASTER_EMAIL"/>
</property>
<!-- property name="insurance">
<column name="INSURANCE"/>
</property-->
<many-to-one name="related"
column="RELATED_ID"
class="Related"
not-null="false"
insert="true"
update="true"
fetch="join"/>
</class>
In EVERY case the generated SQL was:
Code:
select tmaster0_.TMASTER_ID as col_0_0_,
tmaster0_.TMASTER_NAME as col_1_0_,
tmaster0_.TMASTER_LASTNAME as col_2_0_,
tmaster0_.TMASTER_EMAIL as col_3_0_,
related1_.RELATED_NAME as col_4_0_
from tmaster tmaster0_,
related related1_
where tmaster0_.RELATED_ID=related1_.RELATED_ID
The SELECT I use in my code is something like:
Code:
String SQL_QUERY ="select _t.id,
_t.name,
_t.lastName,
_t.email,
_t.related.name
from Tmaster _t";
Query query = session.createQuery(SQL_QUERY);
List <Object>resultado = query.list();
The problem: I need a JOIN into the SQL and not a WHERE because if I have null values in the related column the values won't be returned.
I tried all the many-to-one attributes with no results, even tried a one-to-many association in the "other side" and always there is a damn WHERE.
Any idea?
Greetings