2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.persistence
.hibernate
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.hibernate
.HibernateException
;
16 import org
.hibernate
.event
.spi
.DeleteEvent
;
17 import org
.hibernate
.event
.spi
.DeleteEventListener
;
19 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
25 public class CdmDeleteListener
implements DeleteEventListener
{
27 private static final long serialVersionUID
= -5511287200489449838L;
28 protected static final Logger logger
= Logger
.getLogger(CdmDeleteListener
.class);
31 public void onDelete(DeleteEvent event
) throws HibernateException
{
32 Object entity
= event
.getObject();
33 if(entity
!= null && RelationshipBase
.class.isAssignableFrom(entity
.getClass())) {
34 logger
.info("Deleting " + entity
);
35 deleteRelationship(event
, entity
);
40 public void onDelete(DeleteEvent event
, Set transientEntities
)throws HibernateException
{
41 Object entity
= event
.getObject();
42 if(entity
!= null && RelationshipBase
.class.isAssignableFrom(entity
.getClass())) {
43 logger
.info("Deleting " + entity
);
44 deleteRelationship(event
, entity
);
52 private void deleteRelationship(DeleteEvent event
, Object entity
) {
53 RelationshipBase relationshipEntity
= (RelationshipBase
)entity
;
54 /* if (relationshipEntity.isRemoved()){
55 Set<IRelated> deletedObjects = relationshipEntity.getDeletedObjects();
56 for (IRelated rel : deletedObjects){
58 logger.info("Updating related entity " + rel);
59 Object o = CdmBase.deproxy(rel, CdmBase.class);
60 EntityEntry entry = event.getSession().getPersistenceContext().getEntry(o);
62 // System.out.println();
64 if (!entry.getStatus().equals(Status.DELETED)){
65 event.getSession().update(rel);