[hibernate-issues] [Hibernate-JIRA] Created: (HHH-4059) in set definitions named queries do not work as expected

Stefan Endrullis (JIRA) noreply at atlassian.com
Sat Jul 25 07:12:12 EDT 2009


in set definitions named queries do not work as expected
--------------------------------------------------------

                 Key: HHH-4059
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4059
             Project: Hibernate Core
          Issue Type: Bug
    Affects Versions: 3.3.2
         Environment:   	
« Hide
OS:
Kubuntu 9.04 amd64, kernel 2.6.28-13-generic

Java:
java version "1.6.0_14"
Java(TM) SE Runtime Environment (build 1.6.0_14-b08)
Java HotSpot(TM) 64-Bit Server VM (build 14.0-b16, mixed mode)

Hibernate:
checked out from svn on 25.07.2009.
            Reporter: Stefan Endrullis
         Attachments: code.zip

I've discovered a problem with named queries in hibernate's set definitions. For demonstration I've prepared a very small example implementation. It consists mainly of the following two classes (only most important attributes illustrated):
class Account {
	Set<Transaction> transactions;
}
class Transaction {
	Account from;
	Account to;
}

I mapped both classes and their attribute with the help of hibernate. Thereby I used a named query to retrieve the list of transactions for an account, since this is the only way of avoiding redundance, I think. This is the mapping of the class Account:
<hibernate-mapping>
	<class name="transactiontest.model.Account" table="account">
		<id name="id" length="10">
			<generator class="native"/>
		</id>
		<property name="name" length="255" not-null="true"/>
		<set name="transactions" table="transaction" inverse="true">
			<key/>
			<one-to-many class="transactiontest.model.Transaction"/>
			<loader query-ref="transactions"/>
		</set>
	</class>

	<sql-query name="transactions">
		<load-collection alias="tra" role="transactiontest.model.Account.transactions"/>
		<query-param name="id" type="integer"/>
		select {tra.*}
		from transaction tra
		where tra.from=:id or tra.to=:id
	</sql-query>
</hibernate-mapping>

When I try to get the transactions of an account via the getTransactions() method I do not get the expected result. But the named query seems to be correct because it works  when I call it directly with the account id as parameter.

For a fast reproduction I've created a minimal test program (junit test) and zipped it (see attachment). If you want to test it with your local MySQL database you can use the SQL script setup/mysql_setup.sql to setup the corresponding DB and the DB user.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the hibernate-issues mailing list