db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Al Lofus (JIRA)" <j...@apache.org>
Subject [jira] Created: (OJB-87) Insert when using collection description with indirection table doesn't auto populate foreign keys.
Date Tue, 03 Jan 2006 02:43:02 GMT
Insert when using collection description with indirection table doesn't auto populate foreign
keys.
---------------------------------------------------------------------------------------------------

         Key: OJB-87
         URL: http://issues.apache.org/jira/browse/OJB-87
     Project: OJB
        Type: Bug
  Components: PB-API  
    Versions: 1.0.4    
 Environment: Linux / MySQL
    Reporter: Al Lofus


We have a defined class descriptor with a contained collection descriptor that uses an indirection
table as follows:

<class-descriptor class="com.dchoc.common.entity.LeagueEntity" table="LEAGUES">
	<field-descriptor id="1" name="id" column="ID" jdbc-type="INTEGER" primarykey="true" autoincrement="true"/>
        <field-descriptor id="2" name="name" column="NAME" jdbc-type="VARCHAR"/>
	<field-descriptor id="3" name="createdDate" column="CREATED_DATE" jdbc-type="TIMESTAMP"/>
    <collection-descriptor
     name="members"
     auto-retrieve="true"
     auto-update="object"
     auto-delete="object"
     proxy="true"
     indirection-table="LEAGUE_MEMBERS"
     element-class-ref="com.dchoc.common.entity.LeagueAccountEntity">
		<orderby name="leagueSequence" sort="ASC"/>
		<fk-pointing-to-this-class column="LEAGUE_ID"/>
                <fk-pointing-to-element-class column="LEAGUE_ACCOUNT_ID"/>
    </collection-descriptor>
</class-descriptor>

We have code that creates an instance of this class (LeagueEntity) and populates a collection
called members (with LeagueAccountEntities) that maps to the above collection descriptor and
then attempts to create the LeagueEntity using pBroker.store(obj, ObjectModification.INSERT).
It worked fine with OJB 1.0.1 through 1.0.3. However, I just upgraded us to 1.0.4 today and
the code now throws an exception, as follows:

   [junit] [org.apache.ojb.broker.accesslayer.JdbcAccessImpl] ERROR:
    [junit] * SQLException during execution of sql-statement:
    [junit] * sql statement was 'INSERT INTO LEAGUE_ACCOUNT (ID,LEAGUE_ID,ACCOUNT_ID,LEAGUE_SEQUENCE)
VALUES (?,?,?,?) '
    [junit] * Exception message is [Column 'LEAGUE_ID' cannot be null]
    [junit] * Vendor error code [1048]
    [junit] * SQL state code [23000=INTEGRITY CONSTRAINT VIOLATION]
    [junit] * Target class is 'com.dchoc.common.entity.LeagueAccountEntity'
    [junit] * PK of the target object is [id=242]
    [junit] * Source object: LeagueAccountEntity[accountId: '252', leagueId: null, leagueSequence:
'5', id: '242', ]
    [junit] * The root stack trace is -->
    [junit] * java.sql.SQLException: Column 'LEAGUE_ID' cannot be null
    [junit]     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2847)
    [junit]     at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1531)
    [junit]     at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1347)
    [junit]     at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:958)
    [junit]     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1957)
    [junit]     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1880)
    [junit]     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1741)
    [junit]     at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:101)
    [junit]     at org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeInsert(Unknown
Source)
    [junit]     at org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(Unknown Source)
    [junit]     at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown Source)
    [junit]     at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown Source)
    [junit]     at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown Source)
    [junit]     at org.apache.ojb.broker.core.PersistenceBrokerImpl.storeAndLinkMtoN(Unknown
Source)
    [junit]     at org.apache.ojb.broker.core.PersistenceBrokerImpl.storeCollections(Unknown
Source)
    [junit]     at org.apache.ojb.broker.core.PersistenceBrokerImpl.storeToDb(Unknown Source)
    [junit]     at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown Source)
    [junit]     at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown Source)
    [junit]     at org.apache.ojb.broker.core.PersistenceBrokerImpl.store(Unknown Source)
    [junit]     at org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(Unknown Source)
    [junit]     at org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(Unknown Source)

Now, in stepping into the code, it looks like the LEAGUES entry is *not* being created/inserted
into the database before the attempt is made to do the inserts for the members in the contained
collection. Thus, there is no league ID foreign key available when the inserts for the members
(LEAGUE_MEMBERS) are done. I'm not sure if that is really what's happening, but that's what
it looks like. Note that if I change the collection descriptor to *not* use the indirection-table
attribute and to just use a more typical foreignkey element in place of the fk-pointing-to-this-class
and fk-pointing-to-element-class elements, then the code works and stops throwing the exception.
So the indirection-table attribute seems to be at the heart of the problem.

Note that as a workaround, we are creating the entity with the collection descriptor set to
null, then adding the desired members and updating the entity. This solution seems to be working,
but has the undesired effect of requiring two database hits for each league we want to create.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message