-->
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: Problems with deleting objects with HQL
PostPosted: Tue Dec 18, 2007 12:48 pm 
Beginner
Beginner

Joined: Wed Dec 13, 2006 10:39 am
Posts: 26
Hibernate version: 3.2.2

Mapping documents:
<hibernate-mapping
>
<class
name="com.seqis.kltm.model.db.project.logging.ProjectKLTMLog"
table="kltm_log"
>

<id
name="objectId"
column="object_id"
type="long"
>
<generator class="native">
</generator>
</id>

<list
name="values"
table="kltm_log_values"
lazy="false"
cascade="all"
>

<key
column="log_id"
>
</key>

<index
column="sequence"
/>

<element
column="value"
type="text"
not-null="false"
unique="false"
length="2147483647"
/>

</list>
</class>

</hibernate-mapping>


Full stack trace of any exception that occurs:
18.12.2007 17:40:50 org.hibernate.util.JDBCExceptionReporter logExceptions
WARNUNG: SQL Error: 547, SQLState: 23000
18.12.2007 17:40:50 org.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: Die DELETE-Anweisung verstieß gegen die COLUMN REFERENCE-Einschränkung 'FK7BDAC42DE4A9234'. Der Konflikt trat in der wl4_kltm_hibernate-Datenbank, Tabelle 'kltm_log_values', column 'log_id' auf.
org.hibernate.exception.ConstraintViolationException: could not execute update query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at com.seqis.kltm.model.dbconn.LogActionCleaner.run(LogActionCleaner.java:45)
Caused by: java.sql.SQLException: Die DELETE-Anweisung verstieß gegen die COLUMN REFERENCE-Einschränkung 'FK7BDAC42DE4A9234'. Der Konflikt trat in der wl4_kltm_hibernate-Datenbank, Tabelle 'kltm_log_values', column 'log_id' auf.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:367)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:505)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
... 5 more
org.hibernate.exception.ConstraintViolationException: could not execute update query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at com.seqis.kltm.model.dbconn.LogActionCleaner.run(LogActionCleaner.java:45)
Caused by: java.sql.SQLException: Die DELETE-Anweisung verstieß gegen die COLUMN REFERENCE-Einschränkung 'FK7BDAC42DE4A9234'. Der Konflikt trat in der wl4_kltm_hibernate-Datenbank, Tabelle 'kltm_log_values', column 'log_id' auf.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:367)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2816)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:2254)
at net.sourceforge.jtds.jdbc.TdsCore.getMoreResults(TdsCore.java:631)
at net.sourceforge.jtds.jdbc.JtdsStatement.processResults(JtdsStatement.java:584)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQL(JtdsStatement.java:546)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeUpdate(JtdsPreparedStatement.java:505)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
... 5 more

Name and version of the database you are using: MSSQL Server 2000 8.00.194

The generated SQL (show_sql=true):

Hibernate:
delete
from
kltm_log
where
object_id in (
select
logs2_.object_id
from
kltm_log_action projectklt1_,
kltm_log logs2_
where
projectklt1_.object_id=logs2_.log_action_id
and (
projectklt1_.referenced_object_id is null
)
)

i want to delete a view objects of the type ProjectKLTMLog. each ProjectKLTMLog has a list of strings, so hibernate creates a second table to store the items of the list. now i if i execute the hql:
delete ProjectKLTMLog log where log.id in (...) the sql query above is executed. but the table with the strings is not included in this sql query.
does anyone know how to delete this kind of objects with an hql query?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 18, 2007 1:51 pm 
Beginner
Beginner

Joined: Wed May 16, 2007 7:12 am
Posts: 41
Location: London
cascade deletes?

Code:
<set name="children" inverse="true" cascade="all">
  <key name="PARENT_ID" on-delete="cascade"/>
  <one-to-many class="Child"/>
</set>

_________________
Dinesh Mahadevan

Visit me at http://www.yelani.com/


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 19, 2007 4:03 am 
Beginner
Beginner

Joined: Wed Dec 13, 2006 10:39 am
Posts: 26
hi,

Code:
<list name="values" table="kltm_log_values" lazy="false" cascade="all">
<key column="log_id">
</key>

<index column="sequence"/>

<element column="value" type="text" not-null="false" unique="false" length="2147483647"/>
</list>


this is the mapping of the string list. i dont use session.delete(), instead i want to delete the objects directly in the database ->
session.createyQuery("delete ProjectKLTMLog log where log.id in (...)").executeUpdatee();
As far is i understand the cascade option of the hbm.xml mapping is not used with hql delete.
session.delete() works fine with cascading, but i dont want to load the objects if i can delete them directly in the database with a simple hql.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 19, 2007 4:52 am 
Regular
Regular

Joined: Sat Nov 25, 2006 11:37 am
Posts: 72
If you want deletes to cascade in the database you have to tell your database in the appropriate foreign key definition to do so. If you want cascading deletes not based on foreign keys to execute in the database you would need to define appropriate triggers.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 19, 2007 9:00 am 
Beginner
Beginner

Joined: Wed Dec 13, 2006 10:39 am
Posts: 26
malm66 wrote:
If you want deletes to cascade in the database you have to tell your database in the appropriate foreign key definition to do so. If you want cascading deletes not based on foreign keys to execute in the database you would need to define appropriate triggers.


thx, i added on-delete=cascade so a foreign key with cascading deletion is created. that works fine for me.


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.