5 Replies Latest reply on Oct 8, 2002 2:45 AM by Alexey Loubyansky

    Using CMR, I still want to be able to fetch my foreign keys

    pol.leleux Newbie

      Hello all,

      I'm kind of new to J2EE, JBoss & CMP, CMR. I have several type of relationships in my object model and I made them work using CMR quite easily with XDoclet. I found it was a nice and easy way to put my object model to work and plus it could manage cascade deletes with no code...
      Well, all my objects have a primary key which is a unique id and I naturally use these id's as foreign keys in my relationships.

      Starting the process of implementation, I was disappointed for 2 reasons :

      1) Xdoclet doesn't put the foreign keys in the data objects, the only solution I have is to put them manually in the base class that you can specify and that Xdoclet uses to generate the dataobject

      2) It doesn't seem to be possible to fetch the foreign key without fetching the related object, i.e. you need to code something like "getRelatedObject().getId()" (getRelatedObject() is a CMR getter) where I would like to be able to do something like "getRelatedObjectId()" but there is no way to map a "persistent field" to a foreign key generated by CMR without a "duplicate column" problem... Of course the same problem arises with the putter...
      I think that when you have a lot of relationships, this could leed to big performance problems, I know that there is a cache but still... or is JBoss smart enough to optimize this ? I think there is a lack in the spec...
      or did I miss something ? Is there any kind of other solution ?

      Thanks a lot for your help, I will really appreciate.