-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Uniqueness for multiple columns and joins
PostPosted: Mon Aug 28, 2006 7:08 pm 
Newbie

Joined: Mon Aug 28, 2006 6:40 pm
Posts: 1
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?

_________________
krzs


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.