Hi,
I have two classes, Item and Order mapped as One-to-Many such as:
Code:
class Item...
@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.MERGE, CascadeType.REMOVE, CascadeType.PERSIST }, targetEntity = OrderImpl.class)
@JoinColumn(name = "Item_ID", referencedColumnName = "Item_ID", nullable = false, updatable = false, insertable = true)
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
public Set<Order> getOrders() {
return myOrders;
}
My Order class only have an identifier to the Item class, it does not have a getItem(), only a getItemId(). The association is one to many because that is what it is actually like.
I would like to be able to provide Hibernate with a set of Orders that I have previously loaded. I have enabled second level cache, and it works fine the second time around, but on the very first load (ie nothing in the cache), I would like Hibernate not to fetch my Order to populate my collection. Instead, I want to provide it with the ones that I know for sure are linked to it. Is there a certain way to achieve this? My attempts at not using the CascadeType.REFRESH attribute to try and do this have not worked. Would a many-to-many association work better?
Any help would be appreciated.
Regards,
Greg