I'm a newcomer to java and the play framework (I'm using play 1.2.2 with a local MySQL5 database). I'm trying to query a couple of tables in a database and display the table join results on a web page.
This is what I have in the various bits:
Controller :-
public static void index() {
List<Mutation> mutation_list= Mutation.getDisorderGene();
render(mutation_list);
}
Model :-
public class Mutation extends Model {
public static List<Mutation> getDisorderGene() {
EntityManager entityManager = play.db.jpa.JPA.em();
List<Mutation> muts = entityManager.createNativeQuery("select disorder_name, gene_name from Disorder,Mutation where Disorder.id = Mutation.disorder_id order by disorder_name, gene_name").getResultList();
return muts;
}
View :-
#{list items:mutation_list, as:'mutation'}
<tr>
<td>${mutation.disorder_name}</td>
<td>${mutation.gene_name}</td>
</tr>
#{/list}
And this is the error message I get!
Template execution error
Execution error occured in template /app/views/Stu/index.html. Exception raised was MissingPropertyException : Exception evaluating property 'disorder_name' for java.util.Arrays$ArrayList, Reason: groovy.lang.MissingPropertyException: No such property: disorder_name for class: java.lang.String.
I'm unsure where the problem lies. Is it with the JPA table join query or is something wrong in the view.
Are there any changes in the view I can make to display the columns?
Many thanks.
What if you put the as clausule...
A native query that selects multiple columns by default returns them as
Object[]
, thus yourgetDisorderGene()
should return aList<Object[]>
, and your template should look as follows: