2

I am trying to develop an application with Hibernate and javax.persistence Annotations. I have some troubles in mapping an interface.

I have mapped my interface as @MappedSuperclass and I have already tried to use the attribute targetEntity in my ManyToOne Annotation that referred to the interface and it worked. The problem is that I would more than one class to act as targetEntity. In particular I'd like that every class that implements my interface, could be recognized as a target entity.

Does anybody knows if it's possible to do it?

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
Daniela Mogini
  • 299
  • 1
  • 5
  • 17

1 Answers1

0

I think this

In particular I'd like that every class that implements my interface, could be recognized as a target entity.

is not possible. Only classes which are annotated with @Entity or which are mapped in an other way (for example with a mapping file) can be persisted.

Also, the Hibernate documentation says:

Note

Annotating interfaces is currently not supported.

See the rather old question Interfaces with hibernate annotations for additional information.

Community
  • 1
  • 1
rolve
  • 10,083
  • 4
  • 55
  • 75
  • I think you're right. Infact, I have annotated each class that implements the interface with @Entity and it works whene I choose only one of them to be the target entity. Hope to see interface support in the next version of Hibernate! – Daniela Mogini Sep 26 '12 at 12:21