Hi!
When I use a <properties> element to do a multi-column unique constraint, I get the error "missing FROM-clause entry for table" if I try to access one of my association:
Code:
<hibernate-mapping>
...
<properties name="dataset_contents_dataset_id_key" unique="true">
<many-to-one name="dataset" class="Dataset" fetch="select">
<column name="dataset_id" not-null="true" />
</many-to-one>
<many-to-one name="usrDatatype" class="UsrDatatype" fetch="select">
<column name="type_id" not-null="true" />
</many-to-one>
</properties>
...
</hibernate-mapping>
The result is:Code:
select
this_.id as id3_0_,
this_.version as version3_0_,
this_.dataset_id as dataset3_3_0_,
this_.type_id as type4_3_0_,
this_.tag_lo as tag5_3_0_,
this_.tag_hi as tag6_3_0_
from
cmd.dataset_contents this_
where
this_.dataset_id=?
and usrdatatyp1_.type_name=?
SQL Error: 0, SQLState: 42P01
ERROR: missing FROM-clause entry for table "usrdatatyp1_"
As you can see there is no "inner join" statement added after the from!
But without <properties> I get:Code:
select
this_.id as id3_1_,
this_.version as version3_1_,
this_.dataset_id as dataset3_3_1_,
this_.type_id as type4_3_1_,
this_.tag_lo as tag5_3_1_,
this_.tag_hi as tag6_3_1_,
usrdatatyp1_.id as id30_0_,
usrdatatyp1_.version as version30_0_,
usrdatatyp1_.type_name as type3_30_0_
from
cmd.dataset_contents this_
inner join
cmd.usr_datatype usrdatatyp1_
on this_.type_id=usrdatatyp1_.id
where
this_.dataset_id=?
and usrdatatyp1_.type_name=?
Is this a bug or an error in the mapping?
I also tried changing the fetch option of "usrDatatype" to "join" instead of "select" to force the inner join but the alias generated by hibernate was different and I got the same error:
Code:
select
this_.id as id3_1_,
this_.version as version3_1_,
this_.dataset_id as dataset3_3_1_,
this_.type_id as type4_3_1_,
this_.tag_lo as tag5_3_1_,
this_.tag_hi as tag6_3_1_,
usrdatatyp3_.id as id30_0_,
usrdatatyp3_.version as version30_0_,
usrdatatyp3_.type_name as type3_30_0_
from
cmd.dataset_contents this_
inner join
cmd.usr_datatype usrdatatyp3_
on this_.type_id=usrdatatyp3_.id
where
this_.dataset_id=?
and usrdatatyp1_.type_name=?
I'm using the latest hibernate version (3.2.5 GA) with PostgreSQL...
Thanks
Christian