-->
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: Bulk delete with composite key
PostPosted: Thu Jun 09, 2005 9:56 am 
Newbie

Joined: Wed Apr 06, 2005 1:13 pm
Posts: 13
Hi All,

I´m trying to execute an simple bulk delete estatement in a table that has an composite primary key and it is not working.

Suppose I have an entity (Table1VO) that have an pk mapped attribute to a PK class (Table1PK) that have an id_1 and id_2 fields.

My hql is :

delete Table1VO where pk.id_1 = ?

Hibernate tell me that not recognize the pk.id_1 field.

What I´m doing wrong???

Thanks
Rogerio


Top
 Profile  
 
 Post subject: Re: Bulk delete with composite key
PostPosted: Thu Jun 09, 2005 10:08 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
rogerio.saulo wrote:
Hi All,

I´m trying to execute an simple bulk delete estatement in a table that has an composite primary key and it is not working.

Suppose I have an entity (Table1VO) that have an pk mapped attribute to a PK class (Table1PK) that have an id_1 and id_2 fields.

My hql is :

delete Table1VO where pk.id_1 = ?

Hibernate tell me that not recognize the pk.id_1 field.

What I´m doing wrong???

Thanks
Rogerio


Can you post your mapping files, class files and stack trace as the instructions suggest ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 12:41 pm 
Newbie

Joined: Wed Apr 06, 2005 1:13 pm
Posts: 13
OK, the real table is TBDESKTOP and the POJO TBDesktopVO

The hibernate mapping :

<hibernate-mapping>
<class table="TBDESKTOP" name="br.com.gsb.model.vos.TBDesktopVO">
<composite-id unsaved-value="none" name="pk" class="br.com.gsb.model.vos.TBDesktopKey">
<key-property name="idEntidade">
<column name="ID_ENTIDADE"/>
</key-property>
<key-property name="idAmbiente">
<column name="ID_AMBIENTE"/>
</key-property>
<key-property name="idDesktop">
<column name="ID_DESKTOP"/>
</key-property>
</composite-id>
<property name="dadosDesktop" column="DADOS_DESKTOP"/>
<property name="idAplicativo" column="ID_APLICATIVO"/>
<property name="idParentDesktop" column="IDPARENT_DESKTOP"/>
<property name="nivelDesktop" column="NIVEL_DESKTOP"/>
<property name="nomeTagDesktop" column="NOMETAG_DESKTOP"/>
<property name="ordemDesktop" column="ORDEM_DESKTOP"/>
<property name="tipoRegistroDesktop" column="TIPOREGISTRO_DESKTOP"/>
<many-to-one insert="false" update="false" class="br.com.gsb.model.vos.TBAplicativosVO" name="aplicativo">
<column name="ID_ENTIDADE"/>
<column name="ID_AMBIENTE"/>
<column name="ID_APLICATIVO"/>
</many-to-one>
</class>
</hibernate-mapping>

The POJO

package br.com.gsb.model.vos;

/**
*
* @hibernate.class table="TBDESKTOP"
*/

public class TBDesktopVO extends BaseVO {

private TBDesktopKey pk = null;

private Integer tipoRegistroDesktop = null;
private Integer ordemDesktop = null;
private Integer nivelDesktop = null;
private String nomeTagDesktop = null;
private String dadosDesktop = null;
private String idParentDesktop = null;
private Integer idAplicativo = null;

private TBAplicativosVO aplicativo = null;

/**
* @return Returns the dadosDesktop.
*
* @hibernate.property column="DADOS_DESKTOP"
*/

public String getDadosDesktop() {
return dadosDesktop;
}

/**
* @param dadosDesktop The dadosDesktop to set.
*/

public void setDadosDesktop(String dadosDesktop) {
this.dadosDesktop = dadosDesktop;
}

/**
* @return Returns the idAplicativo.
*
* @hibernate.property column="ID_APLICATIVO"
*/

public Integer getIdAplicativo() {
return idAplicativo;
}

/**
* @param idAplicativo The idAplicativo to set.
*/

public void setIdAplicativo(Integer idAplicativo) {
this.idAplicativo = idAplicativo;
}

/**
* @return Returns the idParentDesktop.
*
* @hibernate.property column="IDPARENT_DESKTOP"
*/

public String getIdParentDesktop() {
return idParentDesktop;
}

/**
* @param idParentDesktop The idParentDesktop to set.
*/

public void setIdParentDesktop(String idParentDesktop) {
this.idParentDesktop = idParentDesktop;
}

/**
* @return Returns the nivelDesktop.
*
* @hibernate.property column="NIVEL_DESKTOP"
*/

public Integer getNivelDesktop() {
return nivelDesktop;
}

/**
* @param nivelDesktop The nivelDesktop to set.
*/

public void setNivelDesktop(Integer nivelDesktop) {
this.nivelDesktop = nivelDesktop;
}

/**
* @return Returns the nomeTagDesktop.
*
* @hibernate.property column="NOMETAG_DESKTOP"
*/

public String getNomeTagDesktop() {
return nomeTagDesktop;
}

/**
* @param nomeTagDesktop The nomeTagDesktop to set.
*/

public void setNomeTagDesktop(String nomeTagDesktop) {
this.nomeTagDesktop = nomeTagDesktop;
}

/**
* @return Returns the ordemDesktop.
*
* @hibernate.property column="ORDEM_DESKTOP"
*/

public Integer getOrdemDesktop() {
return ordemDesktop;
}

/**
* @param ordemDesktop The ordemDesktop to set.
*/

public void setOrdemDesktop(Integer ordemDesktop) {
this.ordemDesktop = ordemDesktop;
}

/**
* @return Returns the pk.
*
* @hibernate.composite-id unsaved-value="none"
*/

public TBDesktopKey getPk() {
return pk;
}

/**
* @param pk The pk to set.
*/

public void setPk(TBDesktopKey pk) {
this.pk = pk;
}

/**
* @return Returns the tipoRegistroDesktop.
*
* @hibernate.property column="TIPOREGISTRO_DESKTOP"
*/

public Integer getTipoRegistroDesktop() {
return tipoRegistroDesktop;
}

/**
* @param tipoRegistroDesktop The tipoRegistroDesktop to set.
*/

public void setTipoRegistroDesktop(Integer tipoRegistroDesktop) {
this.tipoRegistroDesktop = tipoRegistroDesktop;
}

/**
* @return Returns the aplicativo.
*
* @return Returns the tbGruposUsuario.
*
* @hibernate.many-to-one class="br.com.gsb.model.vos.TBAplicativosVO" insert="false" update="false"
*
* @hibernate.column name="ID_ENTIDADE"
* @hibernate.column name="ID_AMBIENTE"
* @hibernate.column name="ID_APLICATIVO"
*/

public TBAplicativosVO getAplicativo() {
return aplicativo;
}


/**
* @param aplicativo The aplicativo to set.
*/

public void setAplicativo(TBAplicativosVO aplicativo) {
this.aplicativo = aplicativo;
}

}

The TestCase code :

Query query = getCurrentSession().createQuery("delete TBDesktopVO where pk.idEntidade = :idEntidade and pk.idAmbiente = :idAmbiente and idAplicativo = :idAplicativo");

query.setString("idEntidade", idEntidade);
query.setString("idAmbiente", idAmbiente);
query.setInteger("idAplicativo", idAplicativo.intValue());

query.executeUpdate();

The error stack trace :

java.lang.Exception: org.hibernate.HibernateException: org.hibernate.QueryException: could not resolve property: idEntidade of: br.com.gsb.model.vos.TBDesktopVO [delete TBDesktopVO where pk.idEntidade = :idEntidade and pk.idAmbiente = :idAmbiente and idAplicativo = :idAplicativo]
at br.com.gsb.services.DesktopService.importDesktop(DesktopService.java:114)
at br.com.gsb.testcases.DesktopServiceTestCase.testDesktopLoader(DesktopServiceTestCase.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)


-----------------------------------------------------------------------------------

Well, if I put in the delete the fields of the table directly than it work, for example :

delete TBDesktopVO where ID_ENTIDADE = :idEntidade and ID_AMBIENTE = :idAmbiente and ID_APLICATIVO = :idAplicativo

But in that way, hibernate simply ignore the mappings and execute the statement only translating the table name, i think that this is not the right way to make the bulk delete.

Thanks in advance
Rogerio


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.