I chose the abstract class route, seems to be working.
Cheers for the assistance!
Bob
Michael Horwitz wrote:
>
> On 7/31/07, syg6 <[EMAIL PROTECTED]> wrote:
>>
>>
>> Hmmm ... another quick (I hope!) question:
>>
>> In my onSaveOrUpdate() or onMerge() methods I need to set the values for
>> two
>> fields - the date of the modification and the user who made the
>> modification. The trouble is that not all of my persisted objects have
>> these
>> fields.
>>
>> So my question - is my only option to do something like this (in the case
>> of
>> a Merge):
>>
>> Object original = event.getOriginal();
>>
>> if (original instanceof Person)
>> {
>> Person person = (Person)original;
>> person.setDateModi(new Date());
>> person.setUserModi(DaoUtils.getUserName());
>> }
>>
>> Do I have to do an 'instanceof' and cast for every class that has the
>> dateModi and userModi fields?
>>
>> Geez ... I hope not. Perhaps I need an abstract base class that has these
>> methods?
>
>
> Could do, or use and interface or use introspection to find the fields and
> act accordingly.
>
> Mike.
>
> Bob
>>
>>
>> syg6 wrote:
>> >
>> > That did the trick! Many thanks!
>> >
>> > Bob
>> >
>> >
>> > Michael Horwitz wrote:
>> >>
>> >> On 7/31/07, syg6 <[EMAIL PROTECTED]> wrote:
>> >>>
>> >>>
>> >>> Hello,
>> >>>
>> >>> I copied into WEB-INF and then deleted the applicationContext-dao.xml
>> >>> that
>> >>> comes in resources (I 'exploded' Appfuse source into my project) and
>> >>> added
>> >>> the following mapping:
>> >>>
>> >>> <bean id="sessionFactory" ...>
>> >>> <property name="eventListeners">
>> >>> <map>
>> >>> <entry key="save-update"><ref local="saveOrUpdateListener"
>> >>> /></entry>
>> >>> </map>
>> >>> </property>
>> >>> </bean>
>> >>> <bean id="saveOrUpdateListener"
>> >>> class="com.mycompany.myapp.dao.SaveOrUpdateListener" />
>> >>>
>> >>> The class, SaveOrUpdateListener, extends the Hibernate
>> >>> DefaultSaveOrUpdateEventListener, and for the moment does nothing
>> more
>> >>> than
>> >>> a System.out. But it's only being called when I save or update the
>> User
>> >>> object. The only other object I have for the moment is Person, and
>> it's
>> >>> just
>> >>> a POJO, it doesn't have its own DAO or Manager. Could this be the
>> reason
>> >>> why
>> >>> my EventListener is not being called?
>> >>
>> >>
>> >> Yas and no. Yes in that your listener is not being called because you
>> are
>> >> using the Generic DAO. No in that you don't need to implement a
>> specific
>> >> DAO
>> >> to solve the problem. See below.
>> >>
>> >> Mind you, most of my objects will have DAOs and Managers, but many
>> will
>> >> be
>> >>> simple POJOs that rely on GenericDaoHibernate and GenericManagerImpl
>> for
>> >>> CRUD. The EventListener should be being called, no?
>> >>
>> >>
>> >> Yes, but there is a catch here. The Generic DAO calls merge, whereas
>> the
>> >> UserDAO call saveOrUpdate on the Hibernate session. So you will see
>> >> activity
>> >> on the User object. If you want your listener to pick up events for
>> >> objects
>> >> going through the Generic DAO you will also need to extend/implement
>> the
>> >> MergeEventListener.
>> >>
>> >> Mike.
>> >>
>> >> Thanks!
>> >>> Bob
>> >>>
>> >>> --
>> >>> View this message in context:
>> >>>
>> http://www.nabble.com/EventListener-only-firing-on-User-object--tf4191374s2369.html#a11919503
>> >>> Sent from the AppFuse - User mailing list archive at Nabble.com.
>> >>>
>> >>> ---------------------------------------------------------------------
>> >>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> >>> For additional commands, e-mail: [EMAIL PROTECTED]
>> >>>
>> >>>
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/EventListener-only-firing-on-User-object--tf4191374s2369.html#a11922234
>> Sent from the AppFuse - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/EventListener-only-firing-on-User-object--tf4191374s2369.html#a11923306
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]