Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Query for entity.collection returns List with one element which is null (instead of empty list)
Query for entity.collection returns List with one element which is null (instead of empty list) [message #1221731] Wed, 18 December 2013 10:09 Go to next message
Pawel Zak is currently offline Pawel ZakFriend
Messages: 8
Registered: November 2012
Junior Member
Hello.

I have 2 entities:

class Person {
	@Id
	@Column(name="id")
	private int id;

	@Column(name="name")
	private String name;

	@OneToMany(cascade = {CascadeType.PERSIST}, fetch = FetchType.LAZY)
	@JoinColumn(name="person_id", referencedColumnName = "id")
	private Set<Phone> phones = new HashSet<Phone>();
}

class Phone {
	@Id
	@Column(name="id")
	private int id;

	@Column(name="number")
	private String number;
}


In DB I have one Person entity persisted, and zero Phone entities.

Following query:
em.createQuery("SELECT p FROM Person p").getResultList()

obviously returns List with one Person row (and I can see that phones list is empty)

This query:
em.createQuery("SELECT p.phones FROM Person p WHERE p.phones IS NOT EMPTY").getResultList()

returns List with zero Phone rows (and it's OK)

But this query:
em.createQuery("SELECT p.phones FROM Person p").getResultList()

return List with one element which is null.

Is that normal behaviour? I would expect empty list over there (or at least null). I didn't find anything about it in JPA specification.

EclipseLink Version: 2.5.1.v20130918-f2b9fc5
JPA Version: 2.1.0.v201304241213


Thank you for your help.
Re: Query for entity.collection returns List with one element which is null (instead of empty list) [message #1243697 is a reply to message #1221731] Tue, 11 February 2014 10:16 Go to previous messageGo to next message
Pawel Zak is currently offline Pawel ZakFriend
Messages: 8
Registered: November 2012
Junior Member
Anyone?
Re: Query for entity.collection returns List with one element which is null (instead of empty list) [message #1243983 is a reply to message #1243697] Tue, 11 February 2014 18:45 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
What happens if you call em.refresh on the person, does the collection show as empty afterward?
Re: Query for entity.collection returns List with one element which is null (instead of empty list) [message #1244341 is a reply to message #1243983] Wed, 12 February 2014 07:33 Go to previous messageGo to next message
Pawel Zak is currently offline Pawel ZakFriend
Messages: 8
Registered: November 2012
Junior Member
Hi.

For problematic query, I'm not querying for Person but for list of Phones. And since there is only one null element (and I don't have Person object) I have nothing to refresh.

When I'm querying for Person, I have empty Phone list which is expected behaviour.
Re: Query for entity.collection returns List with one element which is null (instead of empty list) [message #1245307 is a reply to message #1244341] Thu, 13 February 2014 16:06 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
I misread the original description.

I believe the problem is due to changes in how EclipseLink handles inner join results, made specifically for the case of SELECT count(p.phones) FROM Person p". In earlier releases, EclipseLink would use an inner join for p.phones which would mean no results would be returned even though users would expect a result of 0. I believe the change to support the count query in the select statement is what is forcing the null to be returned in your query.

Feel free to file a bug for it if this behavior is a problem. I believe you should get no results back as you are forcing an inner join between person and phones, but you can change the behavior to be consistent with a small change in the query:
"Select phone from Person p join p.phones phone"
This should return no results instead of a null.

Best Regards,
Chris
Previous Topic:MOXy XPath expression compatibility with DOM and javax.xml.xpath.XPath
Next Topic:Attributes in the default namespace?
Goto Forum:
  


Current Time: Tue Apr 23 13:28:10 GMT 2024

Powered by FUDForum. Page generated in 0.04057 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top