Hello, the following code produces a different result dependent on a check for the list size (proxied/unproxied list).
If there is no check and the list remains in a proxied state, the rank column of the list is inserted as 0. This causes the another entry to occupy the 0 position.
With the check the position is inserted correctly into the database as the last item in the list.
The item is inserted (in the java domain) at the end of the list in both cases. I am using default-access="field"
Code:
public abstract class Person{
protected List<HeldPosition> positions = new ArrayList<>();
...
public HeldPosition assignPosition(Position pos)
{
HeldPosition hp = new HeldPosition(this, pos, new Date());
//positions.size(); <---Uncommenting this line produces the correct result
positions.add(hp);
logger.info(getNameAndId() + " assigned position " + pos.getNameAndId());
return hp;
}
}
Code:
From the servlet that makes the call:
StaffMember user = (StaffMember) ses.get(StaffMember.class, usrStr);
Position pos = (Position) ses.get(Position.class, Long.parseLong(request.getParameter("posSelect")));
user.assignPosition(pos);
ses.saveOrUpdate(user);
ses.getTransaction().commit();
ses.close();
Mapping
Code:
<hibernate-mapping schema="intranet" default-access="field">
<class name="com.humanResources.Person" abstract="true" table="PERSON">
...
<list name="positions" table="HELD_POSITION" cascade="all-delete-orphan" inverse="true" >
<key column="HOLDER" />
<list-index column="RANK" />
<one-to-many class="com.humanResources.HeldPosition" />
</list>
</class>
<class name="com.humanResources.HeldPosition" table="HELD_POSITION">
<id name="id" column="ID">
<generator class="sequence">
<param name="sequence">HELD_POSITION_ID_SEQ</param>
</generator>
</id>
...
<many-to-one name="holder" class="com.humanResources.Person" column="HOLDER" />
<many-to-one name="position" class="com.humanResources.Position" column="POSITION" />
</class>
Database Table
Code:
Correct insertion
ID User Held Position Rank
410 user680 150 0
422 user680 316 1
519 user680 307 2
926 user680 389 3
934 user680 95 4
Incorrect insertion (x2)
ID User Held Position Rank
410 user680 26 0
936 user680 342 0
937 user680 150 0
422 user680 316 1
519 user680 307 2
926 user680 389 3
934 user680 95 4
Can anyone shed some light on this problem? Or should I raise a bug ticket?