Hibernate version:
2.1.1
Mapping documents:
<hibernate-mapping>
<class name="newt.Strain" table="testeditor_strains">
<composite-id name="key" class="newt.StrainKey">
<key-property name="oscode" column="sptr_code" type="string" length="10"></key-property>
<key-property name="name" column="name" type="string" length="255"></key-property>
</composite-id>
<property name="strain" column="strain" type="string" length="255"></property>
<property name="nameclass" column="name_class" type="string" length="50"></property>
</class>
<sql-query name="loadStrainDiff">
select {strain}.sptr_code as {strain.key.oscode},
{strain}.name as {strain.key.name},
{strain}.strain as {strain.strain},
{strain}.name_class as {strain.nameclass}
from strains {strain} EXCEPT
select s.sptr_code,
s.name,
s.strain,
s.name_class
from testeditor_strains
order by {strain.key.oscode} <return alias="strain" class="newt.Strain"/>
</sql-query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
List results = s.getNamedQuery("loadStrainDiff").list();
Full stack trace of any exception that occurs:
database error: net.sf.hibernate.QueryException: Alias [strain.key] does not correspond to any of the supplied return aliases = {[strain]} [
select {strain}.sptr_code as {strain.key.oscode},
{strain}.name as {strain.key.name},
{strain}.strain as {strain.strain},
{strain}.name_class as {strain.nameclass}
from strains {strain} EXCEPT
select s.sptr_code,
s.name,
s.strain,
s.name_class
from testeditor_strains
order by {strain.key.oscode}
]
I then tried:
<sql-query name="loadStrainDiff">
select {strain}.sptr_code as {strainkey.oscode},
{strain}.name as {strainkey.name},
{strain}.strain as {strain.strain},
{strain}.name_class as {strain.nameclass}
from strains {strain} EXCEPT
select s.sptr_code,
s.name,
s.strain,
s.name_class
from testeditor_strains
order by {strainkey.oscode} <return alias="strain" class="newt.Strain"/>
<return alias="strainkey" class="newt.StrainKey"/>
</sql-query>
and got:
database error: net.sf.hibernate.MappingException: No persister for: newt.StrainKey
Name and version of the database you are using:postgreSQL 7.3.2
|