Re: many to many relations and default values for the association table?

From: Andrey Razumovsky (razumovsky.andre..mail.com)
Date: Thu Sep 30 2010 - 17:55:20 UTC

  • Next message: gilbertoca: "Re: many to many relation"

    Hi Marc,

    The easiest way is to set the default value at database level. If this way
    doesn't work for you, here's Cayenne 3 solution, maybe a bit ugly, but the
    one comes first to my mind:
    you can intercept low-level SQL query generation by
    implementing BatchQueryBuilderFactory (extending
    DefaultBatchQueryBuilderFactory). There you can plug your own
    InsertBatchQueryBuilder that will set certain fields for certain
    tables. BatchQueryBuilderFactory can be set via
    DataDomain.setQueryBuilderFactory.

    Hope that works,
    Andrey

    2010/9/30 Marc Guenther <yod..chli.ch>

    > Hi,
    >
    > I have the usual flattened User <<-->> Group many to many relationship with
    > a association table in between. My problem is, in the association table I
    > have an attribute, which I want to set to a certain default value.
    >
    > But when Cayenne creates a new entry in the association table, all
    > attributes except the fk/pks are set to null. Is there any way to specify a
    > default for the attributes there?
    >
    > I tried to also map the association table to an ObjEntity, but that never
    > gets used, this flattened stuff seems to be handled at a lower level.
    >
    > I can of course change my model and handle the assiciation table in the
    > code, but maybe there is an easier way?
    >
    > Thanks,
    > Marc
    >
    >



    This archive was generated by hypermail 2.0.0 : Thu Sep 30 2010 - 17:56:10 UTC