-
1. Re: RandomAccessSubList exception
jkronegg May 22, 2009 2:25 PM (in response to gonorrhea)Please post the full stack trace.
-
2. Re: RandomAccessSubList exception
ivpu Jun 17, 2009 8:37 AM (in response to gonorrhea)Query object return unserializable RandomAccessSubList if there is set maxResults.
If SFSB can't be activated, because is unserializable.
Problem is in org.jboss.seam.framework.Query<T, E> class, which in method truncResultList(List<E> results) return Collection<E>.sublist()
This method must see like this:
protected List<E> truncResultList(List<E> results) { Integer mr = getMaxResults(); if ( mr!=null && results.size() > mr ) { return new ArrayList(results.subList(0, mr)); } else { return results; } }
Or create own abstract class, which extends EntityQuery<E> class and override method getResultList()
@Transactional @Override public List<E> getResultList() { return new ArrayList<E>(super.getResultList()); }
-
3. Re: RandomAccessSubList exception
jkronegg Jun 17, 2009 10:06 PM (in response to gonorrhea)The
new ArrayList
method is not correct because it does not match the subList contract.The List.subList(int,int) contract is to provide a view on the original list, not a shallow copy (see
Range-View Operation
section Sun's Collection tutorial). Thus, operations on the subList are in fact done on the original List.You can try with the following code:
List list1 = new ArrayList(); List list2 = list1.subList(0,0); System.out.println("size="+list1.size()); // size is 0 list2.add("xxx"); System.out.println("size="+list1.size()); // size is 1
If you use the
new ArrayList
trick, you will get the following (notice thenew ArrayList
around list2):List list1 = new ArrayList(); List list2 = new ArrayList(list1.subList(0,0)); System.out.println("size="+list1.size()); // size is 0 list2.add("xxx"); System.out.println("size="+list1.size()); // size is 0
By doing the
new ArrayList
trick, you will break the original behavior of org.jboss.seam.framework.Query.truncResultList(List<E> results).I can agree that you would probably rarely add elements to the list returned by truncResultList, but I would not change this original behavior.
See also OpenJPA JIRA issue OPENJPA-1025 on that topic.
-
4. Re: RandomAccessSubList exception
ivpu Jun 18, 2009 8:56 AM (in response to gonorrhea)Yes, I know about this problem.
Is there any reason how to get serializable sublist?