unexpected token: VALUES near line 1, column 57

17,791

Solution 1

i think you should use

.createNativeQuery(...);

instead of

.createQuery(...);

but I'm not sure about it.

if you are using annotations

@Query(value = "your_query_here", nativeQuery = true)

Solution 2

It looks as though you're trying to use an SQL statement for the query instead of JPAQL, which I don't believe has an Insert Into anyways, although I'm still new to the Play Framework myself so I may be mistaken.

I believe what you should be doing is creating the user you wish to insert, and then persist that object, since you are using JPA.

So your code would look something along these lines:

User u = new User('Doniyor','[email protected]','jurabayev','er');
JPA.em("default").persist(u);
Share:
17,791
doniyor
Author by

doniyor

Python Developer, Django Developer, Fullstack. Ideas. World. Changes. Trace.

Updated on June 19, 2022

Comments

  • doniyor
    doniyor almost 2 years
    JPA.em("default").createQuery("insert into USER (FULLNAME, EMAIL, USERNAME, PASSWORD) " + " VALUES (\'"+fullname+"\',\'"+email+"\',\'"+username+"\',\'"+password+"\');");
    

    is it a wrong query? i get this error:

    [IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: VALUES near line 1, column 57 [insert into USER (FULLNAME, EMAIL, USERNAME, PASSWORD) VALUES ('Doniyor','[email protected]','jurabayev','er');]]
    

    i dont know why this is happening, the query string is actually okay, right?

    would appreciate any help!

    thanks

  • doniyor
    doniyor almost 12 years
    thank you, that did the job, but it didnot save any data into table :(
  • doniyor
    doniyor almost 12 years
    thanks, not it says, [IllegalArgumentException: Unknown entity: models.User]. but User is there.
  • Jeff LaJoie
    Jeff LaJoie almost 12 years
    You need to have User annotated with JPA as an entity, using @Entity. A good example of this can be found on the Play! website: playframework.org/documentation/2.0.1/JavaEbean I'm sure with a bit of Googling you'll be able to find what how to do the annotations for your User class.
  • doniyor
    doniyor almost 12 years
    yeah, but if i put this entity, is gives me this error: PersistenceException: [PersistenceUnit: defaultPersistenceUnit] Unable to configure EntityManagerFactory this is killing me
  • duffy356
    duffy356 almost 12 years
    did you call the .executeUpdate() method of your query object??
  • duffy356
    duffy356 almost 12 years
    the Method .createNativeQuery(...) creates your query for the database, but it doesn't execute it. To execute your query you have to call the method .executeUpdate() on your query object. which would be now .createNativeQuery(...).executeUpdate(); maybe this post could help you: stackoverflow.com/questions/5157051/…
  • doniyor
    doniyor almost 12 years
    whoever you are, you saved me!!! thaaaaaaaaanks a lot! :D. that worked. i didnot use 1) executeUpdate() and 2) setParameter was very important. thanks thanks thanks
  • Adelin
    Adelin over 8 years
    Helped in Hibernate too hahaha