• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Persistence Library parameter problem when using associations

Guest
Nov 18, 2011 Nov 18, 2011

Copy link to clipboard

Copied

Hi,

I've recently started using the Cairngorm Persistence Library and ran into a problem with parameters sometimes not working correctly when using associations.  I'm using the Persistence Library 0.10, Flex 3.5, and AIR 2.0.

The problem seems to be related to parameter names, and I was able to work around it by renaming some of my parameters.  I'm posting about it here to try to determine the cause (and, if it's a bug, hopefully get it fixed).

Below is a simplified example where I'm seeing the problem.

I create two classes, Path and ObjectAssociatedWithPath:

package

{

    public class Path

    {

        [Id]

        [Mapped]

        public var pathId:int;

        [Mapped]

        public var path:String = "C:/";

        public function Path()

        {

        }

    }

}

package

{

    public class ObjectAssociatedWithPath

    {

        [Id]

        [Mapped]

        public var objectId:int;

        [Association]

        public var path:Path;

        public function ObjectAssociatedWithPath()

        {

        }

    }

}

In my SqlMap, I have statements to create and insert items into a PATH table and an OBJECTASSOCIATEDWITHPATH table:

<grammar:Create id="createPathTable">

     CREATE TABLE IF NOT EXISTS PATH( PATHID INTEGER PRIMARY KEY, PATH TEXT )

</grammar:Create>

<grammar:Create id="createObjectAssociatedWithPathTable">

     CREATE TABLE IF NOT EXISTS OBJECTASSOCIATEDWITHPATH( OBJECTID INTEGER PRIMARY KEY, PATHID INTEGER )

</grammar:Create>

<grammar:Insert id="insertPath" type="{ Path }">

     INSERT INTO PATH ( PATH ) VALUES ( :path )

</grammar:Insert>

<grammar:Insert id="insertObjectAssociatedWithPath" type="{ ObjectAssociatedWithPath }">

     INSERT INTO OBJECTASSOCIATEDWITHPATH ( PATHID ) VALUES ( :pathId )

</grammar:Insert>

Finally, I have a function that creates the tables and inserts an object into each of them:

private function parameterTest():void

{

     var sqlSession:ISqlSession = persistenceClient.createSqlSession();

     sqlSession.beginTransaction();

     sqlSession.create("createPathTable", new CreateResponder(resultHandler, faultHandler));

     sqlSession.create("createObjectAssociatedWithPathTable", new CreateResponder(resultHandler, faultHandler));

     var path:Path = new Path();

     var objectAssociatedWithPath:ObjectAssociatedWithPath = new ObjectAssociatedWithPath();

     objectAssociatedWithPath.path = path;

     sqlSession.insertItem("insertPath", path, new InsertResponder(insertResultHandler, faultHandler));

     sqlSession.insertItem("insertObjectAssociatedWithPath", objectAssociatedWithPath, new InsertResponder(insertResultHandler, faultHandler));

     sqlSession.commitTransaction(new CommitTransactionResponder(resultHandler, faultHandler));

}

private function resultHandler():void

{

}

private function insertResultHandler(rowId:Number, rowsAffected:Number):void

{

}

private function faultHandler(error:SQLError):void

{

     var errorMessage:String = "Message: " + error.message + "\nOperation: " + error.operation + "\nDetails: " + error.details;

     Alert.show(errorMessage);

}

When I execute this function, I get the following error:

Mismatch in parameter count. Found 1 in SQL specified and 2 value(s) set in parameters property.

Expecting values for ':pathId'

when it attempts to execute the "insertObjectAssociatedWithPath" statement.  If I rename the "pathId" property to "thePathId" or specify a different parameter name for that property, i.e.,

        [Id]

        [Mapped(parameter="thePathId")]

        public var pathId:int;

it appears to work correctly.

For the Path association, I think the parameter builder might be adding pathId AND path to the parameters property, even though I'm only using the pathId parameter.

Anyone have an idea why this might be happening?

Thanks,

Jay

TOPICS
Cairngorm

Views

3.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Deleted User
Oct 02, 2012 Oct 02, 2012

This is caused by hasNamedParameter function @ NamedParameterBuilder which checks for existance of already added parameters.

You have already added parameter "path" in your mapping, hasNamedParameter() unfortunatelly checks if sqlStatement.text.indexOf(parameter) > -1

and because *:pathId*.indexOf(":path") > -1 the pathId is ommited.

Votes

Translate

Translate
Guest
Oct 02, 2012 Oct 02, 2012

Copy link to clipboard

Copied

This is caused by hasNamedParameter function @ NamedParameterBuilder which checks for existance of already added parameters.

You have already added parameter "path" in your mapping, hasNamedParameter() unfortunatelly checks if sqlStatement.text.indexOf(parameter) > -1

and because *:pathId*.indexOf(":path") > -1 the pathId is ommited.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 02, 2012 Oct 02, 2012

Copy link to clipboard

Copied

LATEST

That explains it.  Thanks for your help!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines