I'm trying to upgrade from 3.0.5 to 3.1. I'm running into a problem where I've got a query like "from Contact where institution = ?" where institution is a property of Contact managed by Hibernate with a foreign key. It looks like Hibernate is just passing "institution" through straight thru to the sql query rather than doing a join with the institutions table.
Is this a bug in 3.1 or is it something that worked before and shouldn't have?
Hibernate version:
3.1
Mapping documents:
Contact.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Contact" table="contacts">
...
<many-to-one name="institution" column="institutionId" />
...
</class>
</hibernate-mapping>
Institution.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Institution" table="institutions">
...
</class>
</hibernate-mapping>
Hibernate query:Code:
from Contact where institution = ?
Full stack trace of any exception that occurs:Code:
org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not execute query; bad SQL grammar [select contact0_.contactId as contactId6_, contact0_.firstName as firstName6_, contact0_.lastName as lastName6_, contact0_.primaryPhone as primaryP4_6_, contact0_.altPhone as altPhone6_, contact0_.street as street6_, contact0_.street2 as street7_6_, contact0_.city as city6_, contact0_.province as province6_, contact0_.postalCode as postalCode6_, contact0_.country as country6_, contact0_.salutation as salutation6_, contact0_.email as email6_, contact0_.gender as gender6_, contact0_.notes as notes6_, contact0_.institutionId as institu16_6_, contact0_.departmentId as departm17_6_, contact0_.contactTitleId as contact18_6_, CONCAT(contact0_.firstName, ' ', contact0_.lastName) as formula0_ from revman_contacts contact0_ where institution=? order by contact0_.lastName]; nested exception is java.sql.SQLException: Unknown column 'institution' in 'where clause'
java.sql.SQLException: Unknown column 'institution' in 'where clause'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2926)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2978)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2902)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:933)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1027)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:91)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:300)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:146)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1093)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at org.springframework.orm.hibernate3.HibernateTemplate$29.doInHibernate(HibernateTemplate.java:826)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:817)
at org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:813)
at com.contentconnections.revman.spring.dao.ContactDaoHibernateSpringImpl.getByInstitution(ContactDaoHibernateSpringImpl.java:31)
at com.contentconnections.revman.test.integration.spring.dao.ContactDaoHibernateSpringImplIntegrationTest.testGetByInstitution(ContactDaoHibernateSpringImplIntegrationTest.java:277)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
Name and version of the database you are using:
MySQL 4.1.14
Debug level Hibernate log excerpt: