You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-user@db.apache.org by Amit Rana <ra...@solis.jp> on 2003/10/21 03:07:47 UTC
class cast exception while inserting
Hi,
I am having problems with inserting a new record in table with
following definition.
<table name="SC_COMMON_ORDERS">
<column name="id" required="true" primaryKey="true"
autoIncrement="true" type="INTEGER"/>
<column name="line_number" required="true" primaryKey="true"
default="1" type="INTEGER"/>
---other columns
</table>
I get a ClassCastException
java.lang.ClassCastException
at
jp.solis.torque.BaseScCommonOrders.setPrimaryKey(BaseScCommonOrders.java
:2404)
at
jp.solis.torque.BaseScCommonOrdersPeer.doInsert(BaseScCommonOrdersPeer.j
ava:675)
at
jp.solis.torque.BaseScCommonOrders.save(BaseScCommonOrders.java:2360)
Any advice on how I can solve it?
I traced the code and the problem is that
BaseScCommonOrdersPeer.doInsert is returning 1 key although it should be
returning an array of keys.
I am using "native" for idbroker so after inserting BasePeer returns
primary key value from the table, In our case we have a composite key so
it should be returning an array not a single value.
Any ideas? Am I doing something wrong?
public void setPrimaryKey(ObjectKey key) throws TorqueException
{
SimpleKey[] keys = (SimpleKey[]) key.getValue(); --throws
exception line 240
SimpleKey tmpKey = null;
setId(((NumberKey)keys[0]).intValue());
setLineNumber(((NumberKey)keys[1]).intValue());
}
Base..Peer's method
public static void doInsert(ScCommonOrders obj, Connection con)
throws TorqueException
{
obj.setPrimaryKey(doInsert(buildCriteria(obj), con)); -- line
675
obj.setNew(false);
obj.setModified(false);
}
/**
* Method to perform inserts based on values and keys in a
* Criteria.
* <p>
* If the primary key is auto incremented the data in Criteria
* will be inserted and the auto increment value will be returned.
* <p>
* If the primary key is included in Criteria then that value will
* be used to insert the row.
* <p>
* If no primary key is included in Criteria then we will try to
* figure out the primary key from the database map and insert the
* row with the next available id using util.db.IDBroker.
* <p>
* If no primary key is defined for the table the values will be
* inserted as specified in Criteria and -1 will be returned.
*
* @param criteria Object containing values to insert.
* @return An Object which is the id of the row that was inserted
* (if the table has a primary key) or null (if the table does not
* have a primary key).
* @throws TorqueException Any exceptions caught during processing
will be
* rethrown wrapped into a TorqueException.
*/
public static ObjectKey doInsert(Criteria criteria) throws
TorqueException
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org