Versions:
- Hibernate 3.2.6.ga
- MySQL 5.1.39
The problem seems to be in manyTomany association. I have two classes created by hbm2java and using annotations, no xml configuration here. Both classes are in persistence.xml. When trying to do the query, i get:
Code:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as col_5_0_, realty0_.rental as col_6_0_, realty0_.sale as col_7_0_ from foo
The whole query created by hibernate is:
Code:
Hibernate: select realty0_.id as col_0_0_, realty0_.street as col_1_0_, realty0.postcode as col_2_0_, town1_.name as col_3_0_, realty0_.area as col_4_0_, . as col_5_0_, realty0_.rental as col_6_0_, realty0_.sale as col_7_0_ from foo.realty realty0_, foo.town town1_ inner join foo.realty_realty_type realty type2_ on realty0_.id=realtytype2_.realty_id inner join foo.realty_type realtytype3_ on realtytype2_.realty_type_id=realtytype3_.id where realty0_.town_id=town1_.id and realty0_.valid=? order by realty0_.area ASC
Classes are Realty and RealtyType. Mapping in Realty to realtyTypes is:
Code:
@ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
@JoinTable(name="realty_realty_type", catalog="foo", joinColumns = {
@JoinColumn(name="realty_id", nullable=false, updatable=false) }, inverseJoinColumns = {
@JoinColumn(name="realty_type_id", nullable=false, updatable=false) })
public Set<RealtyType> getRealtyTypes() {
return this.realtyTypes;
}
Mapping in RealtyType to realties is:
Code:
@ManyToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY)
@JoinTable(name="realty_realty_type", catalog="foo", joinColumns = {
@JoinColumn(name="realty_type_id", nullable=false, updatable=false) }, inverseJoinColumns = {
@JoinColumn(name="realty_id", nullable=false, updatable=false) })
public Set<Realty> getRealties() {
return this.realties;
}
HQL query is:
Code:
SELECT new foo.RealtyWrapper(rty.id, rty.street, rty.postcode, rty.town.name, rty.area, rty.realtyTypes, rty.rental, rty.sale) FROM Realty rty WHERE rty.valid = :valid0 ORDER BY rty.area ASC
So hibernate is forgetting table.column definiton from col_5_0_ definition. Db engine is InnoDB and application is using org.hibernate.dialect.MySQL5InnoDBDialect. What could be the problem?