Are you sure you want to create a list of lists, i.e.:
List<List<String>> listOfLists = ...;
You cannot save both lines and line lists in the same list that is defined in this way. If you really want to do this, you just need to define a List<Object> , and you can store any type of element there. However, this is highly discouraged. Generics were introduced in java to prevent this use at compile time.
So, you probably really want to create a list of row lists, and then run queries that return lists of rows and add the result to the first list:
List<List<String>> list = new LinkedList<List<String>>(); list.addAll(em.createNativeQuery(query1).getResultList()); list.addAll(em.createNativeQuery(query1).getResultList());
By the way, this approach is also not recommended. Usually, if you want to create an n-dimensional collection, where n> 1, you probably should create another container class containing the collection and other materials, and then create a one-dimensional collection that stores instances of this class.
Alexr source share