FAQ
Hello all,

I need to define a relationship between two tables where the keys involved are unique, not primary (the PKs are useless for the join involved).
The relationship can't be inferred from the schema metadata because one of the tables is actually a view.

What I'm seeing in Modeler is a way to define a relationship on primary keys.
I don't see it offering me that on unique keys, nor on an arbitrary selection of fields (which was the last straw that I searched for).
Did I overlook something, or did I hit a limitation?

Well, I *could* work around the problem by defining a view that uses the actual join fields and carries the PKs, and I'd have a PK on at least one side of each join :-)
Except I'd like to avoid cluttering the database namespace with views created just for the sake of Cayenne.

Regards,
Jo

Search Discussions

  • Durchholz, Joachim at Aug 26, 2011 at 9:53 am
    Just to keep people informed: I have found the right incantation.

    As Joel has noted, it's an awful lot of steps.
    Also, Modeler isn't really very intuitive. For example, I'm entirely confused about what you're supposed to do with classes and what should be done with tables. Too many irregularly-formed Lego blocks (possible configuration options), too little explanations how they're supposed to work together.

    Just as a feedback. I'm not working actively with Modeler right now (we had to postpone the Hibernate->Cayenne migration), I'm pretty sure I'll be able to figure it all out once I have more time for this.

    Regards,
    Jo
  • Marc O'Morain at Sep 4, 2011 at 12:12 pm
    Hi Jo,

    I was able to do this in the past by editing the .map.xml file by hand to
    add the relationships. To do this I added a foreign key on the database for
    one table temporarily, and let Cayenne infer this relationship. This
    produced the relationship that I needed. I was then able to delete the
    foreign key, and hand-write the other relationships to match the first.

    It worked surprisingly well, but the real fix is to add foreign keys to your
    database.

    Marc
    On Fri, Aug 26, 2011 at 10:53 AM, Durchholz, Joachim wrote:

    Just to keep people informed: I have found the right incantation.

    As Joel has noted, it's an awful lot of steps.
    Also, Modeler isn't really very intuitive. For example, I'm entirely
    confused about what you're supposed to do with classes and what should be
    done with tables. Too many irregularly-formed Lego blocks (possible
    configuration options), too little explanations how they're supposed to work
    together.

    Just as a feedback. I'm not working actively with Modeler right now (we had
    to postpone the Hibernate->Cayenne migration), I'm pretty sure I'll be able
    to figure it all out once I have more time for this.

    Regards,
    Jo
  • Durchholz, Joachim at Sep 5, 2011 at 1:35 pm

    I was able to do this in the past by editing the .map.xml file by hand to add the relationships. Ouch.
    To do this I added a foreign key on the database for one table temporarily, and let Cayenne infer this relationship. This produced the relationship that I needed. I was then able to delete the foreign key, and hand-write the other relationships to match the first.
    Heh. We wouldn't need to do that, since we do have foreign keys, so we already have a model to work from.
    It worked surprisingly well,
    Good to hear that.
    Though I'd prefer to be able to do that in Modeler. But well, you can't have everything.
    but the real fix is to add foreign keys to your database.
    Not on views.
    I can't even define them at the view level. Not in Oracle anyway.
    And while I'd like the database to automatically infer the constraints on views from those specified at the table level, I'm not visionary enough to actually expect that to be available in my lifetime.

    Regards,
    Jo

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedAug 25, '11 at 10:37a
activeSep 5, '11 at 1:35p
posts4
users2
websitecayenne.apache.org

People

Translate

site design / logo © 2022 Grokbase