Skip to main content

GF v3 + EclipseLink: OneToMany list contains null entries

3 replies [Last post]
cplaetzinger
Offline
Joined: 2008-06-12
Points: 0

I am using GlassFish Server Open Source Edition 3.0.1 (build 22) and have a very strange behavior with entity objects. I have an entity class A. One of the fields is a list of related entity objects of type B:

@Entity
public class A {

@OneToMany( mappedBy="aInstance" )
@OrderBy( "someId" )
private List<B> list = new ArrayList<B>();
}

@Entity
public class B {
@ManyToOne
@JoinColumn( name="id" )
private A aInstance;
}

To get an instance of A the EntityManager.find() method is used. This returns an instance of A. Now
the list is processed using a for-each loop.
for ( B bElement : list ) {
// do something with bElement
}

Sometimes one of the elements in the list is null. If this is the case I have checked the following:
- Logged size of the list (e.g. 30)
- Checked database. The database contains 30 valid entries which should be in the list.
- The last element in the list was null.
- The last element was added in the previous transaction.

Seems the persistence frameworks failed to fill the list correctly.

So here are my questions:
- How can there be null elements in the list?
- What can I do to debug this or provide more information?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
hwellmann
Offline
Joined: 2008-08-16
Points: 0

Do you get the same problem when commenting out the @OrderBy annotation? I had similar issues with an @OrderColumn, which is not quite the same use case, but it might be related. Eclipselink appears to have some bugs with ordered collections.
See http://hwellmann.blogspot.com/2010/09/jpa-20-ordered-collections.html
Regards,
Harald

mmess
Offline
Joined: 2011-01-28
Points: 0

It seems that the issue can be avoided or at least made unlikely to happen when calling the garbage collector directly after deploying the application and before doing something which causes the issue.
This can be tested by connecting a jconsole to Glassfish and clicking on the "Perform GC" button after a deploy or Glassfish-start and before running some tests.

cplaetzinger
Offline
Joined: 2008-06-12
Points: 0

Thanks for your answer. My application requires a sorted list and it would be too much work to change this part.
Cheers
Christian