None of the columns for mappings are found. I tried id_location, id_user with same results.
The sql statement works when used in command line for MySQL.
The actual sql is much more complicated so I made this simple failure case.
Hibernate version:
3.1.2
Mapping documents:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="xxxx.src.model.activity">
<class name="Activity"
table="production.activity"
discriminator-value="ABSTRACT">
<id name="id" column="id" unsaved-value="0">
<generator class="native"/>
</id>
<discriminator column="discriminator" type="string"/>
<property name="type" not-null="true" column="type"/>
<property name="rating" not-null="true" column="rating"/>
<many-to-one name="user"
class="userfactory.src.model.User"
column="id_user"
not-null="true" />
<many-to-one name="location"
class="xxxx.src.model.Location"
column="id_location"
lazy="false"
not-null="true" />
<many-to-one name="supplier"
class="xxxx.src.model.supplier.ActivitySupplier"
column="id_supplier"
not-null="true"
lazy="false"
unique="true" />
...
...
...
Code between sessionFactory.openSession() and session.close():
String sqlDistinct =
"select distinct {a.type},{a.rating},{a.id_supplier} from {a}";
Session session = HibernateSession.currentSession();
SQLQuery q = session.createSQLQuery( sqlDistinct );
q.addEntity( "a", Activity.class );
activityList = q.list();
Full stack trace of any exception that occurs:
org.hibernate.QueryException: No column name found for property [id_supplier] for alias [a] [select distinct {a.type},{a.rating},{a.id_supplier} from {a}]
at org.hibernate.loader.custom.SQLQueryParser.resolveProperties(SQLQueryParser.java:262)
at org.hibernate.loader.custom.SQLQueryParser.substituteBrackets(SQLQueryParser.java:149)
at org.hibernate.loader.custom.SQLQueryParser.process(SQLQueryParser.java:85)
at org.hibernate.loader.custom.SQLCustomQuery.(SQLCustomQuery.java:157)
at org.hibernate.engine.query.NativeSQLQueryPlan.(NativeSQLQueryPlan.java:21)
Name and version of the database you are using:
The generated SQL (show_sql=true):
None produced. Didn't make it this far.
Debug level Hibernate log excerpt:
|