Re: Creating new object in validateForInsert or validateForSave (are you certain?) (Oups...)

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Jan 23 2007 - 08:43:45 EST

  • Next message: Mike Kienenberger: "Re: Self joins"

    Yes, since 2.0.2 is synched from Apache, it is already there:

    http://mirrors.ibiblio.org/pub/mirrors/maven2/org/apache/cayenne/
    cayenne-nodeps/2.0.2/

    (1.2.2 requires assistance from Maven folks, so it is lagging behind)

    Andrus

    On Jan 22, 2007, at 11:39 PM, Alexander Lamb (dev) wrote:

    > Ok, I was with version 2.0.1-incubating (with Maven). Is 2.0.2
    > already available through Maven?
    >
    > On Jan 22, 2007, at 12:01 PM, Andrus Adamchik wrote:
    >
    >> Actually you may want to upgrade to 2.0.2 - you may be affected by
    >> this bug that was fixed in the last release:
    >>
    >> https://issues.apache.org/cayenne/browse/CAY-712
    >>
    >> Andrus
    >>
    >>
    >> On Jan 21, 2007, at 11:10 PM, Alexander Lamb (dev) wrote:
    >>
    >>> Well, it might be me... having trouble with a class hierarchy. So
    >>> first I'll check that, then I'll be back with the
    >>> validateForInsert :-)
    >>>
    >>> On Jan 21, 2007, at 6:49 PM, Alexander Lamb (dev) wrote:
    >>>
    >>>> Hello, me again!
    >>>>
    >>>> Are you certain it is possible to handle fetches and creations
    >>>> in validateForInsert like this for example:
    >>>>
    >>>> public void validateForInsert(ValidationResult validationResult)
    >>>> {
    >>>> Scope scope = Scope.scopeWithShortNameInContext
    >>>> (this.getShortName(),this.getDataContext());
    >>>> if(scope == null)
    >>>> {
    >>>> RegistryScope registryScope = new RegistryScope();
    >>>> this.getDataContext().registerNewObject(registryScope);
    >>>> registryScope.setShortName(this.getShortName());
    >>>> registryScope.setScopeClass("REGISTRY");
    >>>> registryScope.setName(this.getLongName());
    >>>> registryScope.setRegistry(this);
    >>>> }
    >>>> }
    >>>>
    >>>> I get a wonderfull index out of bounds deep in the cayenne classes:
    >>>>
    >>>> java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    >>>> at java.util.ArrayList.RangeCheck(ArrayList.java:546)
    >>>> at java.util.ArrayList.get(ArrayList.java:321)
    >>>> at java.util.Collections$UnmodifiableList.get
    >>>> (Collections.java:1155)
    >>>> at
    >>>> org.apache.cayenne.access.trans.SelectTranslator.appendQueryColumns
    >>>> (SelectTranslator.java:400)
    >>>> at
    >>>> org.apache.cayenne.access.trans.SelectTranslator.buildResultColumns
    >>>> (SelectTranslator.java:338)
    >>>> at
    >>>> org.apache.cayenne.access.trans.SelectTranslator.createSqlString
    >>>> (SelectTranslator.java:113)
    >>>> at
    >>>> org.apache.cayenne.dba.mysql.MySQLSelectTranslator.createSqlString(
    >>>> MySQLSelectTranslator.java:31)
    >>>> at
    >>>> org.apache.cayenne.access.trans.QueryAssembler.createStatement
    >>>> (QueryAssembler.java:95)
    >>>> at
    >>>> org.apache.cayenne.access.jdbc.SelectAction.performAction
    >>>> (SelectAction.java:71)
    >>>> at org.apache.cayenne.access.DataNodeQueryAction.runQuery
    >>>> (DataNodeQueryAction.java:59)
    >>>> at org.apache.cayenne.access.DataNode.performQueries
    >>>> (DataNode.java:273)
    >>>> at
    >>>> org.apache.cayenne.access.DataDomainQueryAction.runQuery
    >>>> (DataDomainQueryAction.java:319)
    >>>> at org.apache.cayenne.access.DataDomainQueryAction.access
    >>>> $000(DataDomainQueryAction.java:60)
    >>>> at org.apache.cayenne.access.DataDomainQueryAction
    >>>> $1.transform(DataDomainQueryAction.java:291)
    >>>> at org.apache.cayenne.access.DataDomain.runInTransaction
    >>>> (DataDomain.java:820)
    >>>> at
    >>>> org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransacti
    >>>> on(DataDomainQueryAction.java:288)
    >>>> at
    >>>> org.apache.cayenne.access.DataDomainQueryAction.execute
    >>>> (DataDomainQueryAction.java:109)
    >>>> at org.apache.cayenne.access.DataDomain.onQuery
    >>>> (DataDomain.java:730)
    >>>> at
    >>>> org.apache.cayenne.util.ObjectContextQueryAction.runQuery
    >>>> (ObjectContextQueryAction.java:217)
    >>>> at
    >>>> org.apache.cayenne.access.DataContextQueryAction.execute
    >>>> (DataContextQueryAction.java:54)
    >>>> at org.apache.cayenne.access.DataContext.onQuery
    >>>> (DataContext.java:1386)
    >>>> at org.apache.cayenne.access.DataContext.performQuery
    >>>> (DataContext.java:1375)
    >>>> at ch.rodano.role.model.Scope.scopeWithShortNameInContext
    >>>> (Scope.java:18)
    >>>> at ch.rodano.role.model.Registry.validateForInsert
    >>>> (Registry.java:39)
    >>>>
    >>>>
    >>>> On Jan 17, 2007, at 8:53 AM, Andrus Adamchik wrote:
    >>>>
    >>>>> Hi Alex,
    >>>>>
    >>>>> Yes you can do that. Validation routine is executed before
    >>>>> object changes are finalized, allowing arbitrary object
    >>>>> operations to be performed during the validation.
    >>>>>
    >>>>> Andrus
    >>>>>
    >>>>>
    >>>>> On Jan 17, 2007, at 12:07 AM, Alexander Lamb (dev) wrote:
    >>>>>
    >>>>>> Hello list,
    >>>>>>
    >>>>>> I am currently using Cayenne 2.0.
    >>>>>>
    >>>>>> I read it was possible to modify objects during a
    >>>>>> validateForInsert or validateForSave call (e.g. not the same
    >>>>>> as old WebObjects).
    >>>>>>
    >>>>>> What about creating a new object and inserting it in the
    >>>>>> DataContext? Will it get saved at the same time?
    >>>>>>
    >>>>>> My problem is the following:
    >>>>>>
    >>>>>> I have an object which has a to-one relationship to another
    >>>>>> object. That other object has to be created at the same time
    >>>>>> as the first one. I would like to make it automatic so the
    >>>>>> user of the library I am writing can simply create and insert
    >>>>>> the first object and the second one will follow.
    >>>>>>
    >>>>>> To understand why I am creating two objects related one-to-one
    >>>>>> it is because I have an entity which can be related (to-one)
    >>>>>> to either one of four other entities. I am doing this instead
    >>>>>> of modeling things with a class hierarchy since cayenne
    >>>>>> doesn't support multiple tables class hierarchies.
    >>>>>>
    >>>>>> Thanks for any hints!
    >>>>>>
    >>>>>> Alex
    >>>>>>
    >>>>>
    >>>>
    >>>
    >>>
    >>
    >
    >



    This archive was generated by hypermail 2.0.0 : Tue Jan 23 2007 - 08:44:22 EST