1

I am trying downloading all records from table in h2 buildin database in playframework. I am facing an error:

[IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: * near line 1, column 8 [SELECT * FROM TABLE]] 

Method CODE i class Table:

@Transactional(readOnly=true)
public static Result view() {
    Query query = JPA.em().createQuery("SELECT * FROM TABLE");
    List<Table> downloaded_from_db = query.getResultList();
    System.out.println(downloaded_from_db.getClass());

    return ok(view.render("none"));
}

Please help me. I would like to see downloaded records in console in simple view. Please give me some tips or good tutorial.

After changing my class loooks like this:

@Transactional(readOnly=true)
public static Result view() {
    List<MedicalIncidents> data = JPA.em()
           .createNativeQuery("SELECT * FROM MedicalIncident")
           //.createQuery("Select m from MedicalIncident m")
           .getResultList();
    System.out.println(data);

AND I think it works, cause I have 2 entries in that table in database:

But System.out.println(data) return in plaay console:

[[Ljava.lang.Object;@70a0c9be, [Ljava.lang.Object;@4c1d12b6]

But it should return this object by model name like in example: computer-database-jpa:

[models.Computer@214c6fde, models.Computer@63728eb3, models.Computer@75f6bcc6, models.Computer@19e3a7ab, models.Computer@3114d8d4, models.Computer@4fa75f78, models.Computer@756ce822, models.Computer@40fc4c68, models.Computer@73fc612c, models.Computer@3e4fcb31]

So I think that there is something wrong with it. Please help

masterdany88
  • 5,041
  • 11
  • 58
  • 132

1 Answers1

1

You mxied SQL queries with JPQL query. The method you used createQuery needs an JPQL query:

SELECT e FROM Entity e

Also please note in JPQL there is no SELECT *. If you want to write a SQL query, use the method em.createNtiveQuery().

V G
  • 18,822
  • 6
  • 51
  • 89
  • It help me thanks. Now I am having another issue. I've edited my post. Look above – masterdany88 Dec 12 '13 at 13:23
  • Please mark this question as solved and post another question. – V G Dec 12 '13 at 13:30
  • @masterdany88 Before asking your new question, see this question/answer for an example: http://stackoverflow.com/questions/17708946/jpa-native-query-select-and-cast-object – V G Dec 12 '13 at 13:39