Hibernate version: 3.1.3
Name and version of the database you are using: PostgresSQL 8
My mapping file:
Code:
<hibernate-mapping>
<class table="MY_TABLE" name="mypackage.TestDocument">
<id name="id">
<generator class="native"/>
</id>
<properties name="doc_unique" unique="true">
<many-to-one column="TEST_ID" not-null="true" name="test"/>
<many-to-one column="DOCUMENT_ID" not-null="true" name="document"/>
</properties>
</class>
</hibernate-mapping>
I'm trying to execute a query joining one of associated table:
Code:
Criteria criteria = session.createCriteria(TestDocument.class);
criteria.add(Restrictions.eq("test", test));
criteria.createAlias("document", "doc");
criteria.addOrder(Order.asc("doc.name"));
result = criteria.list();
And it throws:
Code:
SQLException: ERROR: relation "doc1_" does not exist
Indeed, the SQL seems to be inappropriate (it does not contain the join to the document table):
Code:
select this_.id as id2_0_, this_.TEST_ID as TEST2_2_0_, this_.DOCUMENT_ID as DOCUMENT3_2_0_ from MY_TABLE this_ where this_.TEST_ID=? order by doc1_.NAME asc
However, if I give the uniqueness up and my mapping file is:
Code:
<hibernate-mapping>
<class table="MY_TABLE" name="mypackage.TestDocument">
<id name="id">
<generator class="native"/>
</id>
<many-to-one column="TEST_ID" not-null="true" name="test"/>
<many-to-one column="DOCUMENT_ID" not-null="true" name="document"/>
</class>
</hibernate-mapping>
everything works fine! The SQL is correct:
Code:
select this_.id as id2_1_, this_.TEST_ID as TEST2_2_1_, this_.DOCUMENT_ID as DOCUMENT3_2_1_, doc1_.id as id11_0_, doc1_.NAME as NAME11_0_ from MY_TABLE this_ inner join DOCUMENTS doc1_ on this_.DOCUMENT_ID=doc1_.id where this_.TEST_ID=? order by doc1_.NAME asc
Any ideas? Is it a bug or I'm missing something?