Announcement Announcement Module
No announcement yet.
I can't use an @Embeddable as identifier in several Entities Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • I can't use an @Embeddable as identifier in several Entities


    We've a domain object with a composite key. Imagine something like Location with countryCode, cityCode and postalCode and randomId (table LOCATION with COUNTRY_CODE; CITY_CODE ,POSTAL_CODE, RANDO_ID).

    [NOTE: that's not actually true, but I'm not really inspired to invent anything better)

    This composite key is used in several tables as identifier. Imagine something like Shipment (to a Location), Delivery (to a Location), Invoice (to a Location)...

    Besides, the application uses a legacy database that doesn't have referential integrity, so if there's a relationship to Location, the 4 columns will appear in the table that "points to" Location [well, at least I can make some jokes]

    What I want is to create an @Embeddable that I can use as @EmbeddedId in the appropriate entities (Location, plus Shipment, Delivery and so on) and as reference (@ManyToOne) when necessary (using @JoinColumns for that)

    However, entity --class with --identifierType tries to create the @Embeddable and doesn't work, if the @Embeddable already exists.

    I've tried to create a new identifierType (entity --class ~.domain.OurEntity --table OUR_TABLE --identifierType ~.domain.OurEntityId) in order to use the @Embeddable in this new Id, but it doesn't work either:

    The field embedded command is only applicable to JPA @Entity target types.

    Am I doing something wrong? Is a Roo issue or JPA doesn't allowed what I'm trying to do? (I'm using Hibernate, but it doesn't matter for now)