Announcement Announcement Module
No announcement yet.
MappedSuperclass, class hierarchy and identifier generation confusion Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • MappedSuperclass, class hierarchy and identifier generation confusion

    Hi there,

    This is probably simply a case of user error but I would appreciate some help to clear up my understanding.

    I would like to implement a JPA class hierarchy similar to the following:

    DomainBase (audit fields - references AbstractUsers for lastUpdatedBy and createdBy fields, so circular dependency...(!))
    AbstractUser ( contains general user information like names and a string user id)
    Operator, Consumer, Client (concrete users)

    DomainBase is abstract and annotated with @MappedSuperclass or rather @RooJpaEntity(mappedSuperclass=true).
    AbstractUser is also abstract and must use the same inheritance strategy to be conformant to the JPA spec...(?)

    I have other concrete classes in the hierarchy that inherit from DomainBase and I would like control over the Id generation strategy. It seems that I have two options here:

    1) manually declare an @Id field on each concrete type with a suitable generation strategy and remove the @Id field from DomainBase
    2) override the getId() method from DomainBase and use the @Access annotation to force FIELD type persistence

    A couple of questions/comments:

    Trying to do 1), it seems that Roo always regenerates the id and version fields in DomainBase. I don't seem to be able to stop this. Is this correct? that leaves me with 2) , correct?

    Is the circular dependency between AbstractUser and DomainBase a problem. Can it be resolved?

    Any help appreciated.