-->
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.  [ 3 posts ] 
Author Message
 Post subject: Wie mach ichs? "INSERT INTO T2 SELECT * FROM T1 WHERE (
PostPosted: Fri Mar 14, 2008 5:20 am 
Newbie

Joined: Fri Mar 14, 2008 4:55 am
Posts: 2
Hallo,
ich kann den folgenden SQL zwar erfolgreich auf der DB (Oracle 10g) absetzen, bekomme ihn aber nicht mit Hibernate umgesetzt. Hat jemand eine Idee?
Es geht hierbei um das kopieren von Datensätzen in eine andere Tabelle, welche eine 100%ige Kopie der Quelltabelle ist.
Ich würde ungern auf die Variante mit der Angabe aller Felder umsteigen.
(INSERT INTO T (a, b, c ...usw))

Hibernate version: 3.2

Code between sessionFactory.openSession() and session.close():
transaction = session.beginTransaction();
Query query = session.createQuery("INSERT INTO HIST_TABLE SELECT * FROM ORIG_TABLE WHERE (policyNr = ?)");
query.setString(0, policyNr);
query.executeUpdate();
session.flush();
transaction.commit();


Hibernate message:
org.hibernate.hql.ast.QuerySyntaxException: expecting OPEN, found 'SELECT' near line 1, column 32 [INSERT INTO HIST_TABLE SELECT * FROM foo.bar.ORIG_TABLE WHERE (policyNr = ?)]


Full stack trace of any exception that occurs:
org.hibernate.hql.ast.QuerySyntaxException: expecting OPEN, found 'SELECT' near line 1, column 32 [INSERT INTO HIST_TABLE SELECT * FROM foo.bar.ORIG_TABLE WHERE (policyNr = ?)]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:258)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
at


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 5:35 am 
Beginner
Beginner

Joined: Fri Aug 24, 2007 4:46 am
Posts: 36
Location: Bielefeld / Germany
Wenn Du Native-SQL ausführen willst, dann lies bitte hier mal nach, wie das über Hibernate geht:

http://www.hibernate.org/hib_docs/v3/re ... rysql.html

Falls Du über HQL ein Insert ausführen willst, gibt es da einige Einschränkungen, also mal hier lesen (unten auf der Seite):

http://www.hibernate.org/hib_docs/refer ... batch.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 14, 2008 5:59 am 
Newbie

Joined: Fri Mar 14, 2008 4:55 am
Posts: 2
Danke, ich habs nun via NATIVE-SQL umgesetzt und das funzt prima!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.