-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: OrderColumn with bidirectional many-to-many
PostPosted: Tue Oct 27, 2015 3:17 am 
Newbie

Joined: Tue Oct 27, 2015 2:37 am
Posts: 1
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.