AbstractAggregateRoot and Hibernate JPA

I recently derived a class from AbstractAggregateRoot and attempted to use it as a JPA persisted class using Hibernate.
Upon bootup, the following exception occurred.

Caused by: org.hibernate.MappingException: Could not determine type for: org.axonframework.domain.DomainEventStream, at table: customer, for columns: [org.hibernate.mapping.Column(uncommittedEvents)]

at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:390)

at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:363)

at org.hibernate.mapping.Property.isValid(Property.java:225)

Hibernate is picking up the “getters” in the AbstractAggregateRoot class

and attempting to map them since they aren’t annotated with @Transient.

Is there any workaround for this issue?

Thanks!

Hi,

is there any specific reason why you want Hibernate to look at the methods (getters) instead of just the annotated fields? If not, using fields (which is default, if I’m not mistaken) would be your workaround.
Perhaps you can also override the methods and put an @Transient annotation on the overriding method?

Cheers,

Allard

Yes, I only use annotations, but Hibernate by default will also pick up any “getters” by convention. I’ve never seen a way to fix except using
@Transient, however that is not possible when your @MappedSuperclass is not owned by you (AbstractAggregateRoot).
Also, I have tried subclassing, overriding it and adding the @Transient annotation, but still didn’t work.
I’ve got a work around by embedding it in my own class in which it delegates the calls and appropriately annotates the @Transient methods.
I was just surprised nobody had ran across this already . .

I’ve got it working, but a little bit of a complicated implementation since can’t use AbstractAggregateRoot directly with JPA/Hibernate.

I always use field access, and never saw hibernate try to map any property to a database column.
Did you annotate any of your own getters?

Cheers,

Allard

Just read that the placement of the @Id or @EmbeddedId annotation determines access type. I had always used
annotations on the getters and therefore it tried to map all my getters. Never realized that was how it works.

Thanks!

Yes, I only use annotations, but Hibernate by default will also pick up any “getters” by convention. I’ve never seen a way to fix except using
@Transient, however that is not possible when your @MappedSuperclass is not owned by you (AbstractAggregateRoot).

Annotation @javax.persistence.Access(AccessType.FIELD) is what you are looking for.