[hibernate-dev] Extending hibernate
Emmanuel Bernard
emmanuel at hibernate.org
Wed Feb 6 09:24:16 EST 2013
It's better to use the user forums but here are a few hints.
Depending on the collection type, Hibernate can delete the precise rows
that it needs to. In other cases it has to clean all rows and recreate
them.
It seems you are using a collection that is neither a Set nor an indexed
collection (List, Map) - or mapped as such. Consider @OrderColumn if you
use a List as it's a more correct mapping.
Emmanuel
On Tue 2013-02-05 15:39, Sebastian wrote:
> Hello,
>
> My name is Sebastián Marichal, im Computer Engineer and im from Uruguay.
> Actually im working in a great bearing system, using JavaEE and
> Hibernate as ORM.
>
> We implemented an audit mechanism using triggers in order to know each
> insertion and deletion from the database. Everything is working very
> well, but we noticed that in many-to-many associations , when adding an
> element to a collection, hibernate deletes de full collection and
> inserts each element again. For example:
>
> 1 - We have A with a collection of B elements: A ---> [B1,B2,B3]
>
> 2 - Add another B elemento to the collection: A.addB(B4)
>
> 3 - Hibernate delete all the rows from the mapping table A_B and then
> inserts all the B elements again. Something like this:
>
> A.removeAll(B1,B2,B3)
> A.insert(B1)
> A.insert(B2)
> A.insert(B3)
> A.insert(B4)
>
> We noticed this because the log of the audit mechanism was very dirty,
> where we expected to see "B4 inserted into A_B table" we acctually see
> "B1 deleted from A_B table"
> "B2 deleted from A_B table"
> "B3 deleted from A_B table"
> "B1 inserted into A_B table"
> "B2 inserted into A_B table"
> "B3 inserted into A_B table"
> "B4 inserted into A_B table"
>
>
> We needed to avoid this kind of dirty log, so we decided to implement
> native query for many to many collection manipulation, but this fix
> isn't good enough because the version number (we are using optimistic
> locking) of the entity isn't being updated automatically.
>
> Is there any way to change de add and remove implementation of hibernate
> for many-to-many associations? Maybe extending hibernate? I know that
> there si an extension api but im not sure if it can be used for this
> purpose.
>
> I would like your opinion and suggestions!
>
>
> Thanks you!!
>
> Sebastián Marichal
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev
More information about the hibernate-dev
mailing list