AbstractAggregateRoot and Hibernate JPA

87 views
Skip to first unread message

Shane Turner

unread,
Jan 10, 2016, 8:16:33 PM1/10/16
to Axon Framework Users
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!

Allard Buijze

unread,
Jan 13, 2016, 10:06:05 AM1/13/16
to Axon Framework Users
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

--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shane Turner

unread,
Jan 13, 2016, 10:53:59 AM1/13/16
to Axon Framework Users
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.

Allard Buijze

unread,
Jan 13, 2016, 11:17:05 AM1/13/16
to Axon Framework Users
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

Shane Turner

unread,
Jan 13, 2016, 11:38:06 AM1/13/16
to Axon Framework Users
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!

Benoît Liessens

unread,
Jan 18, 2016, 10:02:31 AM1/18/16
to Axon Framework Users


On Wednesday, 13 January 2016 16:53:59 UTC+1, Shane Turner wrote:
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. 
Reply all
Reply to author
Forward
0 new messages