I'm new to Play and also to hibernate and JPA. I'm using MySql DB and JPA I have included
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;
import play.db.jpa.JPA;
import play.mvc.Controller;
import play.db.jpa.*;
I have this Query
List languages = FormLanguages.findAll();
render(languages);
Which runs correctly, but i want to select based on id, something like this
"select * from FormLanguages where id>10"
When i use like this
Query query = JPA.em().createQuery("select * from FormLanguages");
List<FormLanguages> articles = query.getResultList();
render(articles);
Which gives me IllegalArgumentException error
When use like this
List queryList = FormLanguages.em().createQuery("select * from FormLanguages").getResultList();
render(queryList);
which gives the same error please help me how to write Query
Also suggest me some websites
In your scenario:
List languages = FormLanguages.find("id > ?",10).fetch();
Should work.
This one and also this may help you learn the JPA query language. Once you are familiar with them, using find
you can launch those queries. Or use named queries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With