-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: unexpected token error when executing insert for createQuery
PostPosted: Mon May 29, 2006 10:19 am 
Newbie

Joined: Tue Mar 28, 2006 11:46 am
Posts: 10
Hi,

I am using hibernate 3.1.3. I want to execute an insert statement using createQuery method. When I execute it gives me an error.

Does insert is not supported using createQuery method?

Query query = session.createQuery("INSERT INTO Test (id, id2) VALUES (?, ?)");
query.setParameter(0, 100);
query.setParameter(1, 101);
int numInserted = query.executeUpdate();



[java] Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: VALUES near line 1, column 304 [INSERT INTO Test (id, id2) VALUES (?, ?)]
[java] at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:244)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:155)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
[java] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
[java] at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
[java] at hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
[java] at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
[java] at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
[java] at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)
[java] at hsession.api.HibernateSession.add(HibernateSession.java:141)
[java] ... 20 more
[java] Caused by: line 1:304: unexpected token: VALUES
[java] at org.hibernate.hql.antlr.HqlBaseParser.selectFrom(HqlBaseParser.java:1122)
[java] at org.hibernate.hql.antlr.HqlBaseParser.queryRule(HqlBaseParser.java:702)
[java] at org.hibernate.hql.antlr.HqlBaseParser.selectStatement(HqlBaseParser.java:296)
[java] at org.hibernate.hql.antlr.HqlBaseParser.insertStatement(HqlBaseParser.java:328)
[java] at org.hibernate.hql.antlr.HqlBaseParser.statement(HqlBaseParser.java:165)
[java] at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:238)


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 29, 2006 8:35 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
From the refdocs, section 13.4, "DML-styple Operations":
refdocs wrote:
The pseudo-syntax for INSERT statements is: INSERT INTO EntityName properties_list select_statement. Some points to note:

* Only the INSERT INTO ... SELECT ... form is supported; not the INSERT INTO ... VALUES ... form.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.