AbstractAggregateRoot and Hibernate

Hi group,

I am extending AbstractAggregateRoot for my Hibernate-enabled AR.

Since Hibernate uses the no-arg constructor to load the AR, the id of
my AR is randomly set.

Does this mean I cannot extend AbsAggRoot for my Hibernate ARs?

thanks for info.
Geir

Hi Geir,

there is some trickery going on in the background here. Although the ID is initially set to a random value (necessary for backwords compatibility purposes), it is overridden in an @PostLoad method (performPostLoadInitialization) to the value provided by the database.

So, although perhaps not super-optimal, it will work like expected.

Cheers,

Allard

Allard, thanks for quick answer!

The @PostLoad method is not called when using Hibernate
SessionFactory, like we do, only when using an EntityManager
configuration.

Do you think it would be hard to implement a new
HibernateAbstractAggregateRoot? I might do that.

Geir

Hmm… never thought of that one. Is there an @PostLoad alternative to Hibernate? In fact, all you need to do is make sure the “performPostLoadInitialization” method is called after loading the aggregate from the DB.

Allard

Ok,
I made a public void postLoad()
{ super.performPostLoadInitialization(); } in my AR and called that
after loading in the repository. Works fine.

Thanks,
Geir