JPA entity with a interface attribute, is it possible?

It is really a good idea but unfortunately directly mapping interfaces as an entity attribute is not supported by JPA.

You can only map top level classes directly annotated with @Entity. This top level class may implement an interface though.

This feature has been requested and discussed for a long time.

Also take a look at this and this.

Depending on what you’re trying to accomplish, @Inheritance annotation with table-per-class strategy could be an option.

I hope it helps.

Leave a Comment