users@glassfish.java.net

Re: Extra columns in join table?

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Tue, 24 Jul 2007 11:05:23 +0200

All you can do is to create another entity, for example: PersonService
or something like this with
Many2One Person
Many2One Service
//other properties

Now, Person and Service would have to reference PersonService, where
you can store additional attributes.


2007/7/24, glassfish_at_javadesktop.org <glassfish_at_javadesktop.org>:
> I have a services table and a person table. A person can have access to many services, and a service can be accessed by many persons. To map this relationship, I plan on using a join table (as I've done with several other M-M relationships in the same application).
>
> But what's different here is that there are two access levels. I could solve this by adding a column to the join table called "accesslevel", and this level could be looked up using ordinary SQL.
>
> Since I'm using JPA, this join happens behind the scenes, and I'm able to get a list of persons having access to a service, or get a list of services a person has access to using "getServices()" and "getPersons()" methods in the respective entity classes.
>
> So how can I access this extra column in the join table? Do I need to manually create an additional query to the database?
>
> Or is there another completely different way this should be solved?
>
> Thanks
> Marius Waldal
> [Message sent by forum member 'mariusw' (mariusw)]
>
> http://forums.java.net/jive/thread.jspa?messageID=227894
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>