Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Does a Join Table need an @ID annotation?

Thanks for the detailed response, I'll give it a shot.

On 2/5/09, christopher delahunt <christopher.delahunt@xxxxxxxxxx> wrote:
> Hello Zarar,
> You don't ever "need" the extra database field, it is just an easier way
> out in some situations.  In JPA 1.0, what you could create 3 extra basic
> attributes on your Relation Entity that you would mark as @id, and you
> would make them insertable/updateable =false, so that the relationships
> control the database fields.  You would then need to create a PK class
> for the entity, which would be used with the EntityManager find method.
> In JPA 2.0, there is the concept of Derived ids.  This will allow you to
> mark relationships as @Id, avoiding the extra basic mappings, but you
> will still need to create a Pk class.  This feature was implemented in
> EclipseLink main and is in Tuesday night's build if you wished to test
> it out.
> Since EclipseLink will use the underlying database field values as the
> primary key anyway, you don't even really need the PK class.  You
> potentially could create the descriptor for the Relationship object
> yourself; not rely on annotation processing (and infact remove all the
> annotations so they don't get processed) and create a descriptor and the
> mappings in a customizer method.  This would allow you to get by the
> validation process of not having a PK class for the relation entity.  It
> gets a bit more complicated if you wish to have other entitys reference
> this Relationship object, since you would also have to create these
> mappings manually or get validation exceptions.
> Best Regards,
> Chris
> Zarar Siddiqi wrote:
>> Hi,
>> I have three entities that have a many to many relationship with each
>> other.  The relationship is stored in a join table which is also an
>> entity.  So I have Entity1, Entity2 and Entity3 and a "relational"
>> entity called "EntityRel" which has references to the first three
>> entities (in DDL speak, it's a table with three foreign keys).  I was
>> wondering why I MUST have an extra column  in the EntityRel table
>> mapped to an @Id annotation in the class when I don't really need it
>> or will ever use it.
>> Thoughts?
>> Thanks,
>> Zarar
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx

Back to the top