-->
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.  [ 2 posts ] 
Author Message
 Post subject: Bug? Rank column always being inserted as 0
PostPosted: Thu Jan 09, 2014 11:37 pm 
Newbie

Joined: Wed Nov 09, 2011 4:26 pm
Posts: 2
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?


Top
 Profile  
 
 Post subject: Re: Bug? Rank column always being inserted as 0
PostPosted: Mon May 26, 2014 6:28 pm 
Newbie

Joined: Wed Nov 09, 2011 4:26 pm
Posts: 2
Hi, I'm still having trouble with this.


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

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.