So I'm trying to make a junction table that will handle all the id1<->id2 type of relationships I have. I use a type column in the db that tells me which relationship the two id's refer to. The problem is I have no idea how to map this in hibernate. If I do the normal mappings I've seen, it looks like it would grab all the relationships it sees in the table, even though it should only grab those with type x.
I know that I could use a where clause to say give me only these types, but I was hoping for a more transparent way to do it that would have hibernate figure it out.
If there isn't a way, I'll probably make a seperate table for each many-to-many case just because it'll get fairly confusing in the program otherwise. That, and currently there are only four tables that do that, but I anticipate more in the future which is why I would like to have just one junction table.
Also, just some thoughts about which is better practice when designing a db would be appreciated too (figure the one table will just make things a bit neater since there aren't a bunch of little tables all over the place). The design isn't completely in stone as far as little things like that are concerned.
|