I am running into the exception below whenever I use an entity that I have defined.
org.hibernate.exception.SQLGrammarException: Invalid column name 'coordinator_sycs_coord_id'.
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:122)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
I will post below the entities involved and the query that Hibernate is generating. The context is two entities that have a many-to-many relationship in an association table. I find interesting that the query that Hibernate is generating is changing the column name even when I have it right in my annotations. See below:
@Entity
@Table(name = "sycs_coord")
public class SycsCoordinator {
@Id
@GeneratedValue
@Column(name = "sycs_coord_id")
Long id;
@OneToMany(mappedBy = "club", fetch = FetchType.LAZY)
Set<SycsCoordinatorClub> clubs;
//Standard setters and getters below
}
@Entity
@Table(name = "sycs_coord_clb")
@IdClass(SycsCoordinatorClubPk.class)
public class SycsCoordinatorClub {
@Id
@Column(name = "sycs_coord_id")
Long sycs_coord_id;
@Id
@Column(name = "clb_id")
String clb_id;
@ManyToOne
@PrimaryKeyJoinColumn(name = "sycs_coord_id", referencedColumnName="sycs_coord_id")
SycsCoordinator coordinator;
@ManyToOne
@PrimaryKeyJoinColumn(name = "clb_id", referencedColumnName = "Clb_id")
Club club;
}
I am not including the classes Club and SycsCoordinatorClubPk for now because they seem irrelevant to the problem. The query that Hibernate is generating some times is:
select
clubs0_.club_Clb_Id as club4_0_3_,
clubs0_.clb_id_fk as clb1_3_,
clubs0_.sycs_coord_id as sycs2_3_,
clubs0_.clb_id_fk as clb1_2_2_,
clubs0_.sycs_coord_id as sycs2_2_2_,
clubs0_.club_Clb_Id as club4_2_2_,
clubs0_.coordinator_sycs_coord_id as coordina5_2_2_,
clubs0_.lst_updt_dt as lst3_2_2_,
clubs0_.sycs_coord_secur_grp_cd as sycs6_2_2_,
sycscoordi1_.sycs_coord_id as sycs1_0_0_,
sycscoordi2_.sycs_coord_secur_level_id as sycs4_3_1_
from
sycs_coord_clb clubs0_
left outer join
sycs_coord sycscoordi1_
on clubs0_.coordinator_sycs_coord_id=sycscoordi1_.sycs_coord_id
where
clubs0_.club_Clb_Id=?
Notice that sometimes the column name coordinator_sycs_coord_id appears in the query, even when there is no such name in any of the annotations. Why is this?