jpa - methode JEE implementation -
i implemented method allows me generate test ( entire of question ) automatically problem : method take number of random questions category of questions generated (i have entiƩ category , therefore table too) don't know put category in query. , secondly random() not taked jpql can ?
public list<question> preparerandomtest(int number_of_questions, categorie categorie){ string jpql = "select q question q order random() limit "+number_of_questions ; query query = entitymanager.createquery(jpql); return query.getresultlist(); }
you trying use java persistence query language here, hence solution not taking random account. use native query , build query native sql string, native query plain sql statement without entity object reference (like question). way normal sql keywords random etc read.
native query tutorial
instead of using
string jpql = "select q question q order random() limit "+number_of_questions ;
use:
"select * question category="+category+" order random() limit "+number_of_questions;
additional advice: category string "enum" in code match string value in database category column.
Comments
Post a Comment