I have total 3 tables or entities.
1. @Order - For one Order # there can be Multiple LineItems - For One Order there can be multiple emails too. (This part is working so dont need to look at this)
2. @LineItem - For One Line Item there can be Only 1 LinStatus 3. @LineItem - For One LineItem there can be Only 1 LinFileInfos
4. @LinStatus
5. @LinFileInfos
@Order has the following relationships
@Entity @Table(name = "order_sb") public class Order extends AbstractModel<Long> {
@Id @Column(name = "order_int") private Long id;
@Column(name = "order_tod") private Date orderTodate;
@Column(name = "order_type") private String orderType;
@Column(name = "activity_site") private String activitySite;
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "user_id", insertable = false, updatable = false) private UserReg userId;
@OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "order_int", insertable = false, updatable = false) private List<OrderEmail> orderEmail;
@OneToMany(cascade = CascadeType.ALL) @JoinColumn(name = "order_int", insertable = false, updatable = false) List<LineItem> lineItems; ...getters and setters...
}
@Entity @Table(name = "line_item_sb") public class LineItem extends AbstractModel<Long> {
@Id @Column(name = "item_int") private Long id;
@OneToOne(cascade = CascadeType.ALL) @JoinColumn(name = "item_int", insertable = false, updatable = false) private LinSource lineSources;
@OneToOne(cascade = CascadeType.ALL) @JoinColumn(name = "item_int", insertable = false, updatable = false, referencedColumnName = "item_int") private LinStatus lineStatus; ...getters and setters ...
@Entity @Table(name = "lin_status_sb") public class LinStatus extends AbstractModel<Long> {
@Id @GeneratedValue @Column(name = "lin_status_id") private Long id;
@Column(name = "item_int") private Long itemId;
@Column(name = "state_tod") private Date stateTodate;
@Column(name = "item_status") private Long itemStatus; ...getters and setters ... }
@Entity @Table(name = "lin_file_info_sb") public class LinSource extends AbstractModel<Long> {
@Id @GeneratedValue @Column(name = "lin_file_info_id") private Long id;
@Column(name = "item_int") private Long itemId; ...getters and getters .... }
LinStatus and LiFileInfo dont have any relationships
problem is when I am trying to get to LInStatus from LineItem. The Hibernate is generating the join on a wrong field for example
linstatus1_.item_status as item3_2_0_, linstatus1_.state_tod as state4_2_0_, linsource2_.lin_file_info_id as lin1_1_1_, linsource2_.dataset_name as dataset2_1_1_, linsource2_.datatype_name as datatype3_1_1_, linsource2_.item_int as item4_1_1_ from line_item_sb lineitems0_ left outer join lin_status_sb linstatus1_ on lineitems0_.item_int=linstatus1_.lin_status_id left outer join lin_file_info_sb linsource2_ on lineitems0_.item_int=linsource2_.lin_file_info_id where lineitems0_.order_int=?
the lines: on lineitems0_.item_int=linstatus1_.lin_status_id
should be on lineitems0_.item_int=linstatus1_.item_int
|