-->
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.  [ 2 posts ] 
Author Message
 Post subject: no column name found for <many-to-one> in select disti
PostPosted: Sun May 07, 2006 1:22 pm 
Newbie

Joined: Wed Aug 31, 2005 9:13 am
Posts: 8
Location: Springfield, VA
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:


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 12:59 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You're missing a table name.

select distinct a.type, a.rating, a.id_supplier from MyTable a

What's with the curly braces? What are they for?

_________________
Code tags are your friend. Know them and use them.


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

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.