Hi,
I want to optimize one end of a bidirectional many-to-many relation so that I can use extra-lazy fetching. Since I use lists I need to switch from PersistentBag to PersistentList and for this I need to introduce an @OrderColumn. When I add it to the relevant end of the relation (and of course the "not null" order column to the join table that hibernate requires), everything seems to work fine (extra-lazy fetching works, list item removals are done in no time etc.). But if I add new elements, hibernate (i.e. the underlying database) is claiming that it cannot insert a null value into a column that allows no null values (obviously the new order column is not filled). What am I doing wrong?
Side 1:
Code:
@ManyToMany(fetch = FetchType.LAZY, mappedBy="qualityAssurances")
@OrderColumn(name="idx")
@LazyCollection(LazyCollectionOption.EXTRA)
@NotAudited
private List<DataModule> usedInDataModules = new ArrayList<DataModule>();
Side 2:
Code:
@ManyToMany(fetch = FetchType.LAZY)
@BatchSize(size = 20)
@NotAudited
@JoinTable(name="DM_QA", joinColumns={@JoinColumn(name="dm_id")}, inverseJoinColumns={ @JoinColumn(name="qa_id")})
private List<QualityAssurance> qualityAssurances = new ArrayList<QualityAssurance>();
Code for adding new entries:
Code:
QualityAssurance qa=new ...;
qa.getUsedInDataModules().add(this);
qualityAssurances.add(qa);
session.saveOrUpdate(qa);
[... and later on of course a session.saveOrUpdate(...); for the DataModule...]
The problem seems to be that the OrderColumn is not defined on the owner side (but that is not the side where I need it) und thus it is not taken into account when inserting the new record. But how do I define it correctly?