-->
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.  [ 5 posts ] 
Author Message
 Post subject: INSERT INTO ... SELECT ... and composite-id problem
PostPosted: Mon Jan 23, 2006 10:09 am 
Newbie

Joined: Mon Jan 23, 2006 10:04 am
Posts: 9
Hi,

I've got INSERT INTO ... SELECT ... problems.
When I try to class my statemet, I've got following exception:

org.hibernate.QueryException: can only generate ids as part of bulk insert with either sequence or post-insert style generators

I put all parts of composite-id into values list of insert statement:

insert into IdfKlient(idKlient,dotazID,tabulkaVSabloneID,......


Is it possible to INSERT INTO ... SELECT ... with composite-ids?

I have to use this because of performance issues.

Thanks, helping me.








Hibernate version: 3.1

Mapping documents:


<class name="IdfKlient" table="idfklient" node="cz.aegis.idf.db.model.idf.IdfKlient">
<composite-id>
<key-property name="idKlient" column="idklient" type="string" length="25" />
<key-property name="dotazID" column="dotaz_id" type="long" />
<key-property name="tabulkaVSabloneID" column="sablona_id" type="long" />
</composite-id>
<many-to-one name="dotaz" column="dotaz_id" class="cz.aegis.idf.db.model.query.Dotaz" insert="false" update="false"/>
<many-to-one name="tabulkaVSablone" column="sablona_id" class="cz.aegis.idf.db.model.template.TabulkaVSablone" insert="false" update="false"/>
<property name="ic" column="ic" type="string" length="10" not-null="false"/>
<property name="rc" column="rc" type="string" length="10" not-null="false"/>
<property name="jmeno" column="jmeno" type="string" length="40" not-null="true"/>
<property name="ulice" column="ulice" type="string" length="50" not-null="false"/>
<property name="obec" column="obec" type="string" length="50" not-null="false"/>
<property name="psc" column="psc" type="string" length="5" not-null="false"/>


<property name="status" column="status" type="integer"
precision="3" scale="0" />

<property name="errorCode" column="errorcode" type="integer"
precision="3" scale="0" />

<many-to-one name="metaTypKlienta" column="metatypklienta_id"
embed-xml="false" class="cz.aegis.idf.db.model.ciselniky.MetaTypKlienta" not-null="true">
</many-to-one>




</class>


Full stack trace of any exception that occurs:

org.hibernate.QueryException: can only generate ids as part of bulk insert with either sequence or post-insert style generators [insert into IdfKlient(idKlient,dotazID,tabulkaVSabloneID,obec,status,ulice,ic,psc,rc,jmeno) select dtaklient.idKlient, dotaz.id,tabulkaVSablone.id,dtaklient.obec,dtaklient.status,dtaklient.ulice,dtaklient.ic,dtaklient.psc,dtaklient.rc,dtaklient.jmeno from cz.aegis.idf.db.model.dta.DtaKlient as dtaklient,cz.aegis.idf.db.model.query.Dotaz as dotaz,cz.aegis.idf.db.model.template.TabulkaVSablone as tabulkaVSablone where tabulkaVSablone.id=78 and exists(from cz.aegis.idf.db.model.template.Sablona as sablona where dotaz.sablona=sablona and sablona.hlavniTabulka=tabulkaVSablone and exists(from cz.aegis.idf.db.model.batch.IdfDavka as davka where dotaz.davka=davka and davka.status=21))]
at org.hibernate.hql.ast.HqlSqlWalker.postProcessInsert(HqlSqlWalker.java:547)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.insertStatement(HqlSqlBaseWalker.java:491)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:253)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:218)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:105)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:134)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:113)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1600)
at cz.aegis.idf.db.model.template.TabulkaVSablone.processQuery(TabulkaVSablone.java:134)
at cz.aegis.idf.db.model.template.TabulkaVSablone$$FastClassByCGLIB$$3d9223e0.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:161)
at cz.aegis.idf.db.model.template.TabulkaVSablone$$EnhancerByCGLIB$$4f19ad85.processQuery(<generated>)
at test.ProcessQuery.main(ProcessQuery.java:55)

Name and version of the database you are using:

PostgreSQL 8.1


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 23, 2006 6:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
http://www.hibernate.org/hib_docs/v3/reference/en/html/batch.html#batch-direct


Top
 Profile  
 
 Post subject: I read manual
PostPosted: Tue Jan 24, 2006 2:42 am 
Newbie

Joined: Mon Jan 23, 2006 10:04 am
Posts: 9
I read that manual, Hibernate in Action and two others.

I trace this problem at Hibernate source code and found that, it does not recognize, that all part of primary key are included.
There is a TODO that I guess mean: we have to fix this problem.
See code below:

Code:
org.hibernate.hql.ast.tree.IntoClause

private void visitPropertySpecNodes(AST propertyNode, List types) {
      if ( propertyNode == null ) {
         return;
      }
      // TODO : we really need to be able to deal with component paths here also;
      // this is difficult because the hql-sql grammar expects all those node types
      // to be FromReferenceNodes.  One potential fix here would be to convert the
      // IntoClause to just use a FromClause/FromElement combo (as a child of the
      // InsertStatement) and move all this logic into the InsertStatement.  That's
      // probably the easiest approach (read: least amount of changes to the grammar
      // and code), but just doesn't feel right as then an insert would contain
      // 2 from-clauses
      String name = propertyNode.getText();
      if ( isSuperclassProperty( name ) ) {
         throw new QueryException( "INSERT statements cannot refer to superclass/joined properties [" + name + "]" );
      }


[b]HERE IT TRIES TO RECOGNIZE PRIMARY KEY, BUT DOES NOT, BECAUSE I HAVE COMPOSITE-ID[/b]
      if ( name.equals( persister.getIdentifierPropertyName() ) ) {
         explicitIdInsertion = true;
      }

      if ( persister.isVersioned() ) {
         if ( name.equals( persister.getPropertyNames()[ persister.getVersionProperty() ] ) ) {
            explicitVersionInsertion = true;
         }
      }

      String[] columnNames = persister.toColumns( name );
      renderColumns( columnNames );
      types.add( persister.toType( name ) );

      // visit width-first, then depth
      visitPropertySpecNodes( propertyNode.getNextSibling(), types );
      visitPropertySpecNodes( propertyNode.getFirstChild(), types );
   }


[/b][/code]


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 24, 2006 3:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Oh, an embedded composite identifier. Great...

Yes, I'll have to add support for that at some point. Of course you could also use the non-embedded identifier approach as a work around (i.e. use a "pk class").


Top
 Profile  
 
 Post subject: SQL or native SQl
PostPosted: Wed Jan 25, 2006 12:42 pm 
Newbie

Joined: Mon Jan 23, 2006 10:04 am
Posts: 9
Would it help when I will use SQL instead of HQL?

I've other strange problems using INSERT INTO ... SELECT ..., see: http://opensource2.atlassian.com/projects/hibernate/browse/HHH-1349
for further desctiption. Will SQL help me with that problem?


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