You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Emanuele Maiarelli <ma...@gmail.com> on 2012/10/05 00:22:08 UTC

Cayenne fail to fetch relations calling methods via reflection

I'm facing a problem regarding using Reflection with cayenne 3.0.2

The scenario is the following:

I have a table "Comuni" with a relation 1-N with another table
"Anagrafiche".

Cayenne Maps of the two table looks like that:

    <db-entity name="anagrafiche" schema="public">
      ......
        <db-attribute name="ang_comuni_fk" type="BIGINT" length="8"/>

        <db-attribute name="ang_pk" type="BIGINT" isPrimaryKey="true"
isMandatory="true" length="8"/>
      ....
        <db-key-generator>
            <db-generator-type>ORACLE</db-generator-type>
            <db-generator-name>ai_ang_pk</db-generator-name>
            <db-key-cache-size>1</db-key-cache-size>
        </db-key-generator>
    </db-entity>

    <db-entity name="comuni" schema="public">
        <db-attribute name="comuni_cap" type="CHAR" isMandatory="true"
length="5"/>
        <db-attribute name="comuni_cf_prefix" type="VARCHAR" length="10"/>
        <db-attribute name="comuni_com_istat" type="NUMERIC"
isMandatory="true" length="38"/>
        <db-attribute name="comuni_desc" type="VARCHAR" isMandatory="true"
length="255"/>
        <db-attribute name="comuni_pk" type="NUMERIC" isPrimaryKey="true"
isMandatory="true" length="38"/>
        <db-attribute name="comuni_province_fk" type="NUMERIC" length="38"/>
        <db-key-generator>
            <db-generator-type>ORACLE</db-generator-type>
            <db-generator-name>ai_comuni_pk</db-generator-name>
            <db-key-cache-size>1</db-key-cache-size>
        </db-key-generator>
    </db-entity>

    <db-relationship name="toComuni" source="anagrafiche" target="comuni"
toMany="false">
        <db-attribute-pair source="ang_comuni_fk" target="comuni_pk"/>
    </db-relationship>

    <db-relationship name="anagraficheArray" source="comuni"
target="anagrafiche" toMany="true">
        <db-attribute-pair source="comuni_pk" target="ang_comuni_fk"/>
    </db-relationship>

If i call the method "toComuni" via reflection it fetchs the related
object, but puts it in Hollow state (ex: {<ObjectId:Comuni,
comuni_pk=4615>; hollow; []}).

I also noticed that if i fetch all "Comuni" objects with a select query,
before calling "toComuni" method via reflection, the object state is
correcly as Committed.

The problems comes here, after fetching the relation "toComuni" and getting
object into hollow state, the following exception happen running a query
that fetchs all "Comuni" objects

     org.apache.cayenne.CayenneRuntimeException: [v.3.0.2 Jun 11 2011
09:26:09] Can't find id for {<ObjectId:Comuni, comuni_pk=4615>; committed; [

This kind of problems seems to arise frequently running a  paginated
selectquery, but happened even running a not paginated.

Now i had this problem already in the past, i solved it reverting to
cayenne 2.0.4.

If it is possible i'd like to avoid reverting again.

Any idea or workaround?

Should i try moving to cayenne 3.1 instead of reverting to 2.0.4?

Regards,

Emanuele