RE: Same Table name different Node -> works?

From: Gentry, Michael \(Contractor\) ("Gentry,)
Date: Thu Mar 10 2005 - 17:00:28 EST

  • Next message: Sami Mohammed: "Relationship between tables"

    Actually, a better expression example would've been:

    final Expression expression =
    Expression.fromString("toOrder.toUser.username = $username");
    Map parameter = new HashMap(1);
    parameter.put("username", username); // username = String
    Query query = new SelectQuery(LineItem.class,
    expression.expWithParameters(parameter));
    List list = dataContext.performQuery(query);

    I'm 97% certain that would trip it up ... :-) (The username string not
    being an in-memory CayenneDataObject to match against.)

    /dev/mrg

    -----Original Message-----
    From: Gentry, Michael (Contractor) [mailto:michael_gentr..anniemae.com]

    Sent: Thursday, March 10, 2005 4:21 PM
    To: cayenne-use..bjectstyle.org
    Subject: RE: Same Table name different Node -> works?

    I think lazy loading is the Hibernate term for faulting. Basically you
    have a HOLLOW object in Cayenne which stands in for a real object. The
    HOLLOW object only contains enough data to resolve the object from the
    database. When you try to do something with the hollow object (say, a
    getFirstName()), the getter will realize the object is in a HOLLOW state
    and fault the real values into memory from the database. This is done
    transparently to you, but if you have SQL logging turned on, you can see
    it in action. Also, there are to-one faults and to-many faults. If you
    trip the fault on a to-many relationship, it'll fetch all of the rows
    back at the same time, which tends to be much less expensive.

    As for the Expression issue ...

    Let's say you have a LineItem, with a to-one relationship to Order, with
    a to-one relationship to User. The User resides in your database with
    the extensive user/login data, but all of the other data is in your
    other application DB. Suppose you are wanting to construct a query to
    find all LineItems by a certain user. You could try an expression
    similar to:

    final Expression expression = Expression.fromString("toOrder.toUser =
    $user");
    Map parameter = new HashMap(1);
    parameter.put("user", aUser);
    Query = new SelectQuery(LineItem.class,
    expression.expWithParameters(parameter));
    List list = dataContext.performQuery(query);

    I don't believe that query would work because LineItem and Order are in
    database "B" and User is in database "A". I think for queries with
    relationship queries like that, they must all reside in the same
    database. To be honest, I haven't attempted this, though, but that is
    my understanding (this particular example might work since the User is
    already in memory -- it could be an issue of going from B->A->B again
    within a single Expression). You can have cross-database relationships,
    but I think doing a cross-database query has issues. This can be worked
    around, though.

    /dev/mrg

    PS. If you aren't familiar with the dotted-path notation for specifying
    relationships, you should do a little digging. It is wonderful to use
    in your query expressions and you can use them in your code such as
    painting.readNestedProperty("toGallery.exhibitArray"). Look at the
    JavaDoc for
    http://www.objectstyle.org/cayenne/api/cayenne/org/objectstyle/cayenne/C
    ayenneDataObject.html

    -----Original Message-----
    From: Fredrik Liden [mailto:flide..ranslate.com]
    Sent: Thursday, March 10, 2005 3:45 PM
    To: cayenne-use..bjectstyle.org
    Subject: RE: Same Table name different Node -> works?

    Is faulting the same a lazy loading? Just trying to get the terminology
    down.

    I like the sound of query.setRefreshingObjects(true)! I'll give that a
    shot. That would save me some work.

    What do you mean by the single Expression across both tables at the same
    time? It works ok if the tables have a relationship specified but not if
    you try to join it with any other random table/object?

    -----Original Message-----
    From: Gentry, Michael (Contractor) [mailto:michael_gentr..anniemae.com]

    Sent: Thursday, March 10, 2005 12:10 PM
    To: cayenne-use..bjectstyle.org
    Subject: RE: Same Table name different Node -> works?

    I think I would have two data nodes in the second application: one would
    point to its primary data and the other would point to the first
    application's extensive user/login information. Then model things
    naturally (I don't think you'd need two "User" entities or tables). I
    wouldn't go through the trouble of trying to synchronize a table across
    multiple databases if you can avoid it.

    Also, keep in mind you can form relationships across DataNodes if you
    need to. So one entity could have a join to the User entity, even
    though they reside in different databases. Faulting works fine. The
    big "gotcha" that I know of in this situation is you can't do queries
    (using a single Expression) across both tables at the same time. But
    for something like a User object, you'd probably keep ahold of that in a
    session variable/etc and you could just call setUser(session.getUser())
    methods whenever needed.

    Read-only has nothing to do with caching. You can explicitly force a
    refetch on your query using a query.setRefreshingObjects(true); in your
    code.

    /dev/mrg

    -----Original Message-----
    From: Fredrik Liden [mailto:flide..ranslate.com]
    Sent: Thursday, March 10, 2005 2:49 PM
    To: cayenne-use..bjectstyle.org
    Subject: RE: Same Table name different Node -> works?

    Thanks for respoding Michael.

    We have two different applications located on different servers.
    One app has extensive user information and login information that I want
    to use in the second app as well.

    I was thinking of creating a trimmed down version of a user table in the
    second app and synch it with the first one on a periodical basis, back
    and forth.

    My thought was to have one Node pointing to the first app and a second
    Node pointing to the second app. And both containing a table called USER
    in their map, keeping the first Node's USER table read-only (and
    hopefully prevent caching?) and then copy it's user info over to the
    second user table. Calling both tables USER.

    The reason I separate them is because I'm afraid that when user info
    changes in the first app (ouside of Cayenne) the context won't recognize
    the changes.

    I guess the easiest thing would be to just add one character to
    differentiate them :)

    Do you have any advice on a better solution?

    Thanks!

    Fredrik

    -----Original Message-----
    From: Michael Gentry (Yes, I'm a Contractor)
    [mailto:michael_gentr..anniemae.com]
    Sent: Thursday, March 10, 2005 11:29 AM
    To: cayenne-use..bjectstyle.org
    Subject: RE: Same Table name different Node -> works?

    I use the same table/Java name in one of my models, but across separate
    DataDomains (the name is unique in the DataNode). I don't believe you
    can
    duplicate it within the same DataNode, as Cayenne will not know which DB
    connection to use. I would doubt you could duplicate it within two
    separate
    DataNodes under a common DataDomain.

    Can I ask why you are wanting to do this? There might be a better
    solution
    to your problem.

    /dev/mrg

    -----Original Message-----
    From: Fredrik Liden [mailto:flide..ranslate.com]
    Sent: Thursday, March 10, 2005 12:53 PM
    To: cayenne-use..bjectstyle.org
    Subject: Same Table name different Node -> works?

    Hi,

    Is it possible to use the same table name under different Notes?
    Can they be qualified somehow with the Node info?
    I'm trying to find this on the list but can't seem to find the answer.

    Thanks,

    Fredrik



    This archive was generated by hypermail 2.0.0 : Thu Mar 10 2005 - 17:00:33 EST