views:

32

answers:

1

Hi all. A question about Java-Hibernate-Validator. I need to access to a collection attribute when my validation system intercepts an entity insert/update.

I mean, my model defines A class with a set of B elements.

When I call saveOrUpdate(a), the onSave/onFushDirty method of my interceptor is invoked. In that moment I need to know the size of the collection. Is it possible?

Thanks!

A: 

Well, according the the docs, your onSave method receives the entity you are persisting. At that point you can cast your entity to what you want. You can either check with instanceof or make overloaded methods that accept your different classes. And from there, access your collection.

Bozho
Ummm, that was my first approach. But I had a problem: entity.getCollection is not loaded, I mean, it is empty. But not always, so I can't guess that if it is empty so actually has not elements. Sometimes work, but sometimes not. Any idea about this behaviour?
Alberthoven