-->
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.  [ 4 posts ] 
Author Message
 Post subject: Random gaps in the index colum
PostPosted: Thu Dec 17, 2009 11:43 am 
Newbie

Joined: Thu Dec 17, 2009 11:22 am
Posts: 3
Hi everybody,

I'm using Hibernate 3.x and its extended JPA annotations to model a many to many relationship in my application. In summary, I have two "entity" tables, Workflow and Person plus one "relationship" table, WorkflowCoordinator. For each workflow there must be one or more persons, and each person may appear in zero, one or more workflows.

I modelled this with the following code:

public class Workflow {...

// Workflow Coordinators
@ManyToMany (fetch=FetchType.LAZY)
@CollectionId (columns=@Column (name="Id$"), type=@Type (type="int"), generator="idSequence")
@SequenceGenerator (name="idSequence", sequenceName="S$Id", initialValue=1, allocationSize=1)
@JoinTable (name="WorkflowCoordinator", joinColumns={ @JoinColumn (name="Workflow") }, inverseJoinColumns={ @JoinColumn (name="Person") })
@IndexColumn (name="Pos", base=0)
protected java.util.List<com.mycompany.model.Person> workflowCoordinators;

The three tables, Workflow, Person and Workflowcoordinator, have "Id$" as primary key. The Workflowcoordinator has a foreign key to Workflow (column name is "workflow") and another foreign key to Person ( column name is "person" ). As I need to keep the order that was used to assign the coordinators to a given workflow ( because there is the concept of "main" coordinator ), I added a column named "pos" in the WorkflowCoordinator table. Example

Workflow(id$=100) ---> WorkflowCoordinator(id$=750, workflow=100, person=3500, pos=0) <--- Person (id=3500)
Workflow(id$=100) ---> WorkflowCoordinator(id$=760, workflow=100, person=3600, pos=1) <--- Person (id=3600)
Workflow(id$=100) ---> WorkflowCoordinator(id$=790, workflow=100, person=3500, pos=2) <--- Person (id=3700)
...
Workflow(id$=200) ---> WorkflowCoordinator(id$=9950, workflow=200, person=3500, pos=0) <--- Person (id=3999)
Workflow(id$=200) ---> WorkflowCoordinator(id$=9951, workflow=200, person=3600, pos=1) <--- Person (id=3500)

So, in this example, the person whose id$=3500 appears in two workflows as coordinator, and the given workflows have several coordinators.

The problem I have is that sometimes I can see that there's a "gap" in the list of coordinators. For instance:

Workflow(id$=100) ---> WorkflowCoordinator(id$=750, workflow=100, person=3500, pos=0) <--- Person (id=3500)
Workflow(id$=100) ---> WorkflowCoordinator(id$=760, workflow=100, person=3600, pos=1) <--- Person (id=3600)
Workflow(id$=100) ---> WorkflowCoordinator(id$=790, workflow=100, person=3500, pos=3) <--- Person (id=3700)

In this example, the pos=2 is missing ... and this causes a NullPointerException when Hibernate tries to populate the java.util.List of Person ( please see above workflowCoordinators property in the Workflow class )

Thank you very much in advance, and apologies if this case has been answered in othe post, but I haven't been able to see it.

Best regards,

TomCasas


Top
 Profile  
 
 Post subject: Re: Random gaps in the index colum
PostPosted: Thu Dec 17, 2009 12:01 pm 
Regular
Regular

Joined: Thu Dec 10, 2009 10:53 am
Posts: 50
Where do you "see" that one of the coordinators is missing? What's written to the database?

Quote:
Workflow(id$=100) ---> WorkflowCoordinator(id$=790, workflow=100, person=3500, pos=3) <--- Person (id=3700)


Is there a mismatch between the person IDs or is it a typo?


Top
 Profile  
 
 Post subject: Re: Random gaps in the index colum
PostPosted: Thu Dec 17, 2009 1:15 pm 
Newbie

Joined: Thu Dec 17, 2009 11:22 am
Posts: 3
Hi Kossmo,

Yes, it's a typo, I meant:

Workflow(id$=100) ---> WorkflowCoordinator(id$=790, workflow=100, person= * 3700 *, pos=3) <--- Person (id=3700)

When I say that one of the coordinators is missing, I mean that there's a gap in the pos column, that is, the database contains

Workflow(id$=100) ---> WorkflowCoordinator(id$=750, workflow=100, person=3500, pos=0) <--- Person (id=3500)
Workflow(id$=100) ---> WorkflowCoordinator(id$=760, workflow=100, person=3600, pos=1) <--- Person (id=3600)
Workflow(id$=100) ---> WorkflowCoordinator(id$=790, workflow=100, person=3700, * pos=3 * ) <--- Person (id=3700)

Instead of

Workflow(id$=100) ---> WorkflowCoordinator(id$=750, workflow=100, person=3500, pos=0) <--- Person (id=3500)
Workflow(id$=100) ---> WorkflowCoordinator(id$=760, workflow=100, person=3600, pos=1) <--- Person (id=3600)
Workflow(id$=100) ---> WorkflowCoordinator(id$=790, workflow=100, person=3700, * pos=2 * ) <--- Person (id=3700)

The "gaps" may appear in the first position (meaning: pos=1,2,3 instead of pos=0,1,2, or pos=0,2,3,4 instead of pos=0,1,2,3 ) I know, this looks "crazy", but the problem is that sometimes the pos values for a given list of workflowcoordinators contains "holes, gaps" in the pos values. And this causes the NullPointerException when Hibernate tries to load the list of coordinators of the affected workflow.

Thanks for your attention,

TomCasas


Top
 Profile  
 
 Post subject: Re: Random gaps in the index colum
PostPosted: Wed Dec 30, 2009 11:27 am 
Newbie

Joined: Thu Dec 17, 2009 11:22 am
Posts: 3
Hello again,

I haven't found result on my investigations, so far. But I've added some log statements in some methods (marking them with the @PostPersist, @PreUpdateand and @PostUpdate annotations ) and hopefully, I'll see what may cause the error. In that case, I'll let you know what I found.

In the meanwhile, any idea would be really appreciated.

Thanks and ... Happy New Year !!!

TomCasas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.