I have recently upgrade our project from Hibernate 4.1.9 to 4.3.1. We have an account and a training model objects. And in the account model, we have a many-to-many join table to link the trainings:
Code:
@Entity
@Table(name="account")
public class Account {
private Integer id;
...
private List<Training> trainings = new ArrayList<Trainings>(0);
...
@OrderBy("completionDate desc")
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinTable(
name = "account_training",
joinColumns = { @JoinColumn(name = "account_id") },
inverseJoinColumns = @JoinColumn(name = "training_id")
)
public List<Training> getTrainings() {
return trainings;
}
...
}
/** Training Model **/
@Entity
@Table(name="training")
public class Training {
private int id;
private TrainingMethod method;
private DateTime completionDate;
...
}
It runs without any Exception before the upgrade. But after the upgrade to 4.3.1. I receive the following error:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'trainings9_.completion_date' in 'order clause'
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
java.lang.reflect.Constructor.newInstance(Unknown Source)
com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
com.mysql.jdbc.Util.getInstance(Util.java:381)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3515)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3447)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2554)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1761)
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1912)
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
org.apache.tomcat.dbcp.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:80)
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.getResultSet(AbstractLoadPlanBasedLoader.java:449)
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeQueryStatement(AbstractLoadPlanBasedLoader.java:202)
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:137)
org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:102)
org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:186)
org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:4120)
org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:502)
org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:467)
org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:212)
org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:274)
org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:150)
org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1066)
org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:985)
org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:673)
org.hibernate.type.EntityType.resolve(EntityType.java:489)
org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:170)
org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:144)
org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1114)
org.hibernate.loader.Loader.processResultSet(Loader.java:972)
org.hibernate.loader.Loader.doQuery(Loader.java:920)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
org.hibernate.loader.Loader.doList(Loader.java:2551)
org.hibernate.loader.Loader.doList(Loader.java:2537)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2367)
org.hibernate.loader.Loader.list(Loader.java:2362)
org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:496)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:387)
org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:229)
org.hibernate.internal.SessionImpl.list(SessionImpl.java:1260)
org.hibernate.internal.QueryImpl.list(QueryImpl.java:103)
Here is a shorten version of the SQL script:
Code:
SELECT account0_.id AS id1_0_0_, account0_.account_type_id AS account18_0_0_,
account0_.challenge_error_attempts AS challeng2_0_0_, account0_.user_id AS user_id3_0_0_,
...
FROM account account0_ LEFT OUTER JOIN vao account0_1_ ON account0_.id=account0_1_.id
...
LEFT OUTER JOIN account_training trainings9_ ON account0_.id=trainings9_.vao_id
LEFT OUTER JOIN training training10_ ON trainings9_.training_id=training10_.id
...
WHERE account0_.id=?
ORDER BY trainings9_.completion_date DESC;
It is incorrectly used the table alias on the join table "account_training" instead of the actual "training" table. Any idea if this is a bug in 4.3.1?
Thanks,
ltong