-->
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: delete object with filter
PostPosted: Wed May 16, 2007 4:52 am 
Newbie

Joined: Wed May 16, 2007 3:57 am
Posts: 3
Hi,

I define filter in my POJO.

This filter works fine if I load a POJO with "findById" or if I get my POJO via Criteria

But if I want to delete my POJO, Hibernate doesn't apply my filter

it's normal ?

How can I apply my filter when I delete POJO ?



I work with Hibernate 3.2.3.

My mapping file where I define a filter :

<hibernate-mapping>
<class name="com.steria.emma.divers.migration.hibernate.modeles.Acteur" table="ACTEUR" schema="USEREMMA">
<id name="id" type="long">
<column name="ID" precision="22" scale="0" />
<generator class="sequence"><param name="sequence">SEQ_Acteur</param></generator>
</id>
<property name="datedebutvalidite" type="date">
<column name="DATEDEBUTVALIDITE" unique="true" length="7" />
</property>
<property name="datefinvalidite" type="date">
<column name="DATEFINVALIDITE" length="7" />
</property>
<property name="nom" type="string">
<column name="NOM" length="50" not-null="true" />
</property>
<property name="identifiant" type="string">
<column name="IDENTIFIANT" length="20" not-null="true" unique="true" />
</property>
<property name="codeeic" type="string">
<column name="CODEEIC" length="20" not-null="true" />
</property>
<property name="typeacteur" type="integer">
<column name="TYPEACTEUR" precision="1" scale="0" not-null="true" />
</property>
<property name="modecalculssy" type="integer">
<column name="MODECALCULSSY" precision="1" scale="0"/>
</property>

<filter name="dateDebutValiditeFilter" condition=":dateDebutValidite = DATEDEBUTVALIDITE"/>
</class>

<!-- Filtre sur la date de début de validité -->
<filter-def name="dateDebutValiditeFilter">
<filter-param name="dateDebutValidite" type="date"/>
</filter-def>
</hibernate-mapping>


My code :

private void exemple() {

//date : today
Date today = new Date(System.currentTimeMillis());
Date yesterday = new Date(System.currentTimeMillis()-86400000);

//a first acteur
Acteur acteur = new Acteur();
acteur.setCodeeic("Greg");
acteur.setNom("Greg");
acteur.setIdentifiant("Matt");
acteur.setTypeacteur(0);
acteur.setModecalculssy(1);
acteur.setDatedebutvalidite(today);

//a second acteur
Acteur acteur2 = new Acteur();
acteur2.setCodeeic("Greg 2");
acteur2.setNom("Greg 2");
acteur2.setIdentifiant("Matt 2");
acteur2.setTypeacteur(0);
acteur2.setModecalculssy(1);
acteur2.setDatedebutvalidite(yesterday);

//a temporary acteur
Acteur acteurById = null;

Transaction trx = mdh.currentSession().beginTransaction();
mdh.currentSession().saveOrUpdate(acteur);
mdh.currentSession().saveOrUpdate(acteur2);

acteurById = (Acteur)mdh.currentSession().get(Acteur.class,acteur.getId());
System.out.println(acteurById.getNom());

List l = mdh.currentSession().createQuery( "from Acteur" ).list();
for (int i=0;i<l.size();i++){
System.out.println(l.get(i));
}

mdh.currentSession().createQuery( "delete from Acteur" ).executeUpdate();

trx.commit();
mdh.closeSession();
}


My code where I manage my session :

public Session currentSession() throws HibernateException {
Session s = (Session) session.get();
if (s == null|| !s.isOpen()) {
s = sessionFactory.openSession();
s.enableFilter("dateDebutValiditeFilter").setParameter("dateDebutValidite", new Date(System.currentTimeMillis());
session.set(s);
}
return s;
}


SQL generated with paramter value

[varnat] DEBUG [2007-05-16 10:47:19,666] SQL.log(401) | select SEQ_Acteur.nextval from dual
[varnat] DEBUG [2007-05-16 10:47:19,916] SQL.log(401) | select SEQ_Acteur.nextval from dual
Greg
[varnat] DEBUG [2007-05-16 10:47:20,182] SQL.log(401) | insert into USEREMMA.ACTEUR (DATEDEBUTVALIDITE, DATEFINVALIDITE, NOM, IDENTIFIANT, CODEEIC, TYPEACTEUR, MODECALCULSSY, ID) values (?, ?, ?, ?, ?, ?, ?, ?)
[varnat] DEBUG [2007-05-16 10:47:20,197] DateType.nullSafeSet(133) | binding '16 mai 2007' to parameter: 1
[varnat] DEBUG [2007-05-16 10:47:20,197] DateType.nullSafeSet(126) | binding null to parameter: 2
[varnat] DEBUG [2007-05-16 10:47:20,197] StringType.nullSafeSet(133) | binding 'Greg' to parameter: 3
[varnat] DEBUG [2007-05-16 10:47:20,197] StringType.nullSafeSet(133) | binding 'Matt' to parameter: 4
[varnat] DEBUG [2007-05-16 10:47:20,197] StringType.nullSafeSet(133) | binding 'Greg' to parameter: 5
[varnat] DEBUG [2007-05-16 10:47:20,213] IntegerType.nullSafeSet(133) | binding '0' to parameter: 6
[varnat] DEBUG [2007-05-16 10:47:20,213] IntegerType.nullSafeSet(133) | binding '1' to parameter: 7
[varnat] DEBUG [2007-05-16 10:47:20,213] LongType.nullSafeSet(133) | binding '58' to parameter: 8
[varnat] DEBUG [2007-05-16 10:47:20,213] SQL.log(401) | insert into USEREMMA.ACTEUR (DATEDEBUTVALIDITE, DATEFINVALIDITE, NOM, IDENTIFIANT, CODEEIC, TYPEACTEUR, MODECALCULSSY, ID) values (?, ?, ?, ?, ?, ?, ?, ?)
[varnat] DEBUG [2007-05-16 10:47:20,213] DateType.nullSafeSet(133) | binding '15 mai 2007' to parameter: 1
[varnat] DEBUG [2007-05-16 10:47:20,229] DateType.nullSafeSet(126) | binding null to parameter: 2
[varnat] DEBUG [2007-05-16 10:47:20,229] StringType.nullSafeSet(133) | binding 'Greg 2' to parameter: 3
[varnat] DEBUG [2007-05-16 10:47:20,229] StringType.nullSafeSet(133) | binding 'Matt 2' to parameter: 4
[varnat] DEBUG [2007-05-16 10:47:20,229] StringType.nullSafeSet(133) | binding 'Greg 2' to parameter: 5
[varnat] DEBUG [2007-05-16 10:47:20,229] IntegerType.nullSafeSet(133) | binding '0' to parameter: 6
[varnat] DEBUG [2007-05-16 10:47:20,229] IntegerType.nullSafeSet(133) | binding '1' to parameter: 7
[varnat] DEBUG [2007-05-16 10:47:20,229] LongType.nullSafeSet(133) | binding '59' to parameter: 8
[varnat] DEBUG [2007-05-16 10:47:20,229] SQL.log(401) | select acteur0_.ID as ID69_, acteur0_.DATEDEBUTVALIDITE as DATEDEBU2_69_, acteur0_.DATEFINVALIDITE as DATEFINV3_69_, acteur0_.NOM as NOM69_, acteur0_.IDENTIFIANT as IDENTIFI5_69_, acteur0_.CODEEIC as CODEEIC69_, acteur0_.TYPEACTEUR as TYPEACTEUR69_, acteur0_.MODECALCULSSY as MODECALC8_69_ from USEREMMA.ACTEUR acteur0_ where ? = acteur0_.DATEDEBUTVALIDITE
[varnat] DEBUG [2007-05-16 10:47:20,229] DateType.nullSafeSet(133) | binding '16 mai 2007' to parameter: 1
[varnat] DEBUG [2007-05-16 10:47:20,244] LongType.nullSafeGet(172) | returning '58' as column: ID69_
com.steria.emma.divers.migration.hibernate.modeles.Acteur@18bbf55
[varnat] DEBUG [2007-05-16 10:47:20,260] SQL.log(401) | delete from USEREMMA.ACTEUR


Top
 Profile  
 
 Post subject: UP
PostPosted: Thu Jun 07, 2007 3:53 am 
Newbie

Joined: Wed May 16, 2007 3:57 am
Posts: 3
UP


Top
 Profile  
 
 Post subject: up
PostPosted: Wed Jul 11, 2007 9:00 am 
Newbie

Joined: Wed May 16, 2007 3:57 am
Posts: 3
up


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.