I am trying to figure out how to create a (named?) query that will join my entities together. Can I use object properties for the new entity and still do this? I can't seem to decipher how that will/should look.
I have 2 tables, an order and order_assoc table. For ever re-order created in the order table an entry will be created in order_assoc. Also, a re-order can be based on a previous order. So, I have a column in order_assoc that tells me the order which it was based on.
For example, a re-order 4 is created which was based on a previous 1. So, now the assoc table will look like.
order order_assoc
------ -------------
1 new 1 <-pk 4 1
2 new
3 new
4 reorder
I have an existing entity class for order. I added a reference (new entity) to the assoc table
@OneToOne(fetch = FetchType.LAZY, optional = true, cascade = {CascadeType.ALL},
mappedBy = "onlineAdoptionEntity", targetEntity = OnlineAdoptionReOrderAssocEntity.class)
private OnlineAdoptionReOrderAssocEntity reOrderAssocEntity;
The new entity looks like this.
@Id
@Column(name = "OA_REORDER_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "reOrderNumberSeq")
@SequenceGenerator(name = "reOrderNumberSeq", sequenceName = "REORDER_NUMBER_SEQ", allocationSize=1)
private Long id;
@OneToOne(optional = true,cascade = CascadeType.ALL)
@JoinColumn(name="OA_ADOPTION_ID")
private OnlineAdoptionEntity onlineAdoptionEntity;
@ManyToOne(optional = true)
@JoinColumn(name="OA_ORIGINAL_ADOPTION_ID_ASSOC")
private OnlineAdoptionEntity baseReOrderAdoption;
Any help would be great thanks very much. I saw there was a similar post here - it is just not clear to me after reading this post.