java - JPA Unknown Column in Field List -
i have relation between accommodation
, booking
classes, , set foreign key in booking table.
alter table `project`.`booking` add index `fk_accid_fk_idx` (`accommodation` asc); alter table `project`.`booking` add constraint `fk_accid_fk` foreign key (`accommodation`) references `project`.`accommodation` (`id`) on delete no action on update no action;
accommodation class:
@entity .... public class accommodation implements serializable { @id @generatedvalue(strategy = generationtype.identity) @column(name = "id", unique = true, nullable = false) private biginteger id; @onetomany(mappedby = "accommodation", fetch = fetchtype.eager, cascade = cascadetype.remove) @jsonmanagedreference private list < booking > bookings; ......getters setters }
booking class:
@entity public class booking implements serializable { ...... @manytoone(fetch = fetchtype.eager) @joincolumn(name = "bookings", nullable = true) @jsonbackreference private accommodation accommodation; ....getters setters }
when execute query listing accommodations, unknown column in field list error.
javax.persistence.persistenceexception: org.hibernate.exception.sqlgrammarexception: not extract resultset] root cause com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: unknown column 'bookings7_.bookings' in 'field list'
even set relation , define foreign key in table, reason error?
try define join-table mapping manually in jpa. drop schema , let jpa create tables:
accommodation class
@onetomany(mappedby = "accommodation", fetch = fetchtype.eager, cascade = cascadetype.remove) @jsonmanagedreference private list < booking > bookings;
booking class
@manytoone(fetch = fetchtype.eager) @jointable(name = "accommodation_booking_join_table", joincolumns = {@joincolumn(name="booking_id")}, inversejoincolumns = @joincolumn(name = "accommodation_id")) @jsonbackreference private accommodation accommodation;
Comments
Post a Comment