Reputation: 545
I have a function that return an ArrayList< String > ,the list contain elements retrieved from database using JPA ,my problem is that I can't understand the format of the output!
the function is:
public ArrayList<String> getMyListEnvironment()
{
ArrayList<String> env=new ArrayList<String>();
try{
EntityTransaction entr=em.getTransaction();
entr.begin();
javax.persistence.Query multipleSelect= em.createQuery("SELECT h.hEnv FROM HPe h WHERE h.hPePK.pePlatform = :w ").setParameter("w", "platf1");
List s = new LinkedList();
s= multipleSelect.getResultList();
env = new ArrayList(s);
entr.commit();
return env;
}
catch (Exception e )
{
System.out.println(e.getMessage());
System.out.println("error");
}
finally {
em.close();
}
return env;
}
The output(Result):
[DTOMonito.HEnv[ envUrl=http://10.55.99.5:1055 ], DTOMonito.HEnv[ envUrl=http://10.55.99.99:8090 ]]
Upvotes: 0
Views: 131
Reputation: 140011
The query is returning the list of hEnv
found as fields of the the HPe
entity (seems like these abbreviations for the entities cause more confusion than good - it's a good idea to use descriptive names for these type of things).
Is HPe.hEnv
a String? Perhaps your output is confusing because someone is storing a formatted string in this field. Without seeing your code, this is very hard to decipher.
Btw, this method is a bit wasteful for creating dead stores. There is absolutely no point in writing something like this:
List s = new LinkedList();
s= multipleSelect.getResultList();
You could save a line of code (and a LinkedList allocation) by just writing
List s = multipleSelect.getResultList();
Upvotes: 1