From: Paul S. <pau...@ne...> - 2002-02-14 11:10:52
|
Okay, I think we're (almost?) on the same page. I'm *not* advocating a heavy framework that does a whole bunch of magic for you, like maintaining integrity of bidirectional associations. Where a bidirectional association exists simply tweak the relational mapping. For example to avoid "doubling up" on foreign keys to provide visibility from both ends as is done now in a one-to-many. This gives the possibility of integrity checking, which in my experience is very useful once the database gets large and/or complex. No extra API should be needed - it's still non-intrusive. Hibernate shouldn't manage the integrity of the association - the programmer still has to ensure both ends match. The code should be no different if the class is being persisted or not, at least in this respect. PaulS. Gavin_King/Cirrus%CI...@ci... wrote: >>Your statement about such a concept being alien to idiomatic Java to me >>seems to be putting the horse before the cart. While true, I think that >>it loses sight of what we're building - for me at least that's the >>object model. >> > > Hmmmmmmm. Perhaps. I was very keen to stay with the current approach of > just adding persistence to Java, not trying to add any extra semantics, not > trying to build an application framework. If you manage to convince me that > its possible to do bidirectional associations with no xtra API then I'm > sold on it. > > >>There are ways to do this, and all the commercial O/R tools that I've >>used support this. Basically the association is "managed" from one end >>when it comes to persisting the association - and it's straightforward >>to tell when things are screwy. >> > > Interesting. The thing I've used that does bi-directional associations - > namely Visual Age for Java's EJB associations - uses a generated class that > ensures association integrity from _both_ ends. Its arguably not a good > design and is not consistent with the approach in this project. (I think > they have a more difficult problem though, because the ends of the > association might be remote.) > > >>I don't see the problem. Your code (i.e. not Hibernate, the users code) >>is still responsible for making sure all the persistent objects point >>to the right places. This is true without persistence, and I wouldn't >>expect the persistence layer to do this for you - that would be intrusive. >> > (snip) > >>Yep - and that's fine. And if you wanted to you *could* do a consistency >>check quite transparently. There's actually huge advantages in being >>able to do that. >> > > Yeah, I was thinking about this on the way home, after firing off that last > email and thinking "Well, you could just let the users manage integrity > themselves, but validate the state before we persist anything" ... All we > would need to implement this approach is some code to validate the > association somewhere. There wouldn't need to be any other changes to the > runtime engine and there wouldn't need to be any API. This would make me > happy. > > I've been thinking of one-to-many associations while I've been writing > this, but I think much the same thing goes for many-to-manys (where its a > collection on each end - mapped to the one table). |