I can confirm this problem;
The mapping
<class name="GroupMembers" table="GroupMembers">
<composite-id>
<key-property name="keyGroupID" column="groupID" type="int"/>
<key-property name="keyMID" column="MID" type="int"/>
</composite-id>
<property name="linkType" column="linkType" type="string"/>
<!-- a few more properties -->
<property name="comments" column="comments" type="string"/>
<many-to-one name="Groups" class="Groups" column="groupID" insert="false" update="false"/>
<many-to-one name="MedicalRecord" class="MedicalRecord" column="MID" insert="false" update="false"/>
</class>
The generated SQL
HQL: from GroupMembers
SQL: select groupmembe0_.groupID as groupID, groupmembe0_.MID as MID, groupmembe0_.linkType as linkType, groupmembe0_.reviewSts as reviewSts, groupmembe0_.masterFlag as masterFlag, groupmembe0_.adtFlag as adtFlag, groupmembe0_.userName as userName, roupmembe0_.lastUpdate as lastUpdate, groupmembe0_.comments as comments, groupmembe0_.groupID as groupID, groupmembe0_.MID as MID from GroupMembers groupmembe0_
net.sf.hibernate.SQL (BatcherImpl.java:237) : - select groupmembe0_.groupID as groupID, groupmembe0_.MID as MID,
groupmembe0_.linkType as linkType, groupmembe0_.reviewSts as reviewSts,groupmembe0_.masterFlag as masterFlag, groupmembe0_.adtFlag as adtFlag, groupmembe0_.userName as userName, groupmembe0_.lastUpdate as lastUpdate, groupmembe0_.comments as comments, groupmembe0_.groupID as groupID, groupmembe0_.MID as MID from GroupMembers groupmembe0_
The Exception.
net.sf.hibernate.impl.BatcherImpl (BatcherImpl.java:241) : - preparing statement
net.sf.hibernate.util.JDBCExceptionReporter (JDBCExceptionReporter.java:36) : - SQL Exception com.sybase.jdbc2.jdbc.SybSQLException: Select expression results in more than one column having same name. Column name 'groupID' is specified
more than once
at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2708) ......
I have also tried changing the
<key-property name="somethingElse" to avoid this column name collision, but the SQL generator doesn't seem to reflect the name changes. It is determined to keep using the column="groupID" instead of name="keyGroupID"
So the the generated SQL is of the format
"select column as column"
instead of "select column as name"
This is also causing the SQL to incorrect for the <many-to-one>
I hope that help, I need a fix for this; For the time being I've removed the <many-to-one> relations.
|