Question

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','ikbola-86@bk.ru','jurabayev','er');]]

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

would appreciate any help!

thanks

Was it helpful?

Solution

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)

OTHER TIPS

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','ikbola-86@bk.ru','jurabayev','er');
JPA.em("default").persist(u);

This will also do.......

String hql = String.format("insert into attendence(slip_change_cntr,roll_no)values(0,"+a+")");
    Query query = sessionHb.createSQLQuery(hql);
    return query.executeUpdate();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top