Hi,
I'm new to OJB. I'm having trouble inserting 1 new object. The object
I'm inserting is a DebtSecurity. It has a 1:1 relationship
with a DebtOption. However, not all securities have options, so it
sometimes might be a 1:0 relationship.
The DebtSecurity has a composite primary key (CusipID and PositionCode)
and the DebtOption just has CusipID as a primary key.
So in DebtSecurity, CusipID is a foreign-key and also part of a
primary key.
When I create a new DebtSecurity (without an attached DebtOption), and
then try to store it,
I get an error saying CusipID has been set to null, and the
DebtSecurity table doesn't allow null values.
Here's my stacktrace:
[org.apache.ojb.broker.accesslayer.JdbcAccess] ERROR: SQLException
during the execution of the insert: The column CusipID in table
DebtSecurity does not allow null values.
The column CusipID in table DebtSecurity does not allow null values.
com.sybase.jdbc2.jdbc.SybSQLException: The column CusipID in table
DebtSecurity does not allow null values.
at com.sybase.jdbc2.tds.Tds.processEed(Tds.java:2636)
at com.sybase.jdbc2.tds.Tds.nextResult(Tds.java:1996)
at
com.sybase.jdbc2.jdbc.ResultGetter.nextResult(ResultGetter.java:69)
at
com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:204)
at
com.sybase.jdbc2.jdbc.SybStatement.nextResult(SybStatement.java:187)
at
com.sybase.jdbc2.jdbc.SybStatement.updateLoop(SybStatement.java:1615)
at
com.sybase.jdbc2.jdbc.SybStatement.executeUpdate(SybStatement.java:1598)
at
com.sybase.jdbc2.jdbc.SybPreparedStatement.executeUpdate(SybPreparedStatement.java:89)
at
org.apache.ojb.broker.accesslayer.JdbcAccess.executeInsert(JdbcAccess.java:195)
at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(PersistenceBrokerImpl.java:1673)
at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(PersistenceBrokerImpl.java:1593)
at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(PersistenceBrokerImpl.java:1580)
at
com.fanniemae.paa.alexpriced.frameworks.validation.TestOJB.createDebtSecurityTest
I tracked down the problem to the PersistenceBrokerImpl class. I
think the assertFkAssignment method is setting CusipID to null because
there's no DebtOption attached. I understand why assertFkAssignment is
doing what it's doing; but I'm hoping there's a solution to my problem.
Perhaps I should change it to a 1:N relationship instead?
I appreciate any comments.
(I'm using Sybase Jconnect JDBC driver and OJB 0.9.4)
Thanks,
-Victor K. Chang
Here's my xml mapping file:
class-descriptor
class="com.fanniemae.paa.alexpriced.dao.DebtSecurity"
table="DebtSecurity">
<field-descriptor id="1"
name="cusipID"
column="CusipID"
jdbc-type="VARCHAR"
primarykey="true"
nullable="false"/>
<field-descriptor id="2"
name="positionCode"
column="PositionCode"
jdbc-type="VARCHAR"
primarykey="true"
nullable="false"/>
<field-descriptor id="3"
name="capFlrStrikeRate"
column="CapFlrStrikeRate"
jdbc-type="DOUBLE"
nullable="true"/>
...etc...
<!-- to-one relationship template -->
<reference-descriptor
name="debtOptions"
class-ref="com.fanniemae.paa.alexpriced.dao.DebtOption">
<foreignkey field-id-ref="1"/>
</reference-descriptor>
</class-descriptor>
<class-descriptor
class="com.fanniemae.paa.alexpriced.dao.DebtOption"
table="DebtOption">
<field-descriptor id="1"
name="cusipID"
column="CusipID"
jdbc-type="VARCHAR"
primarykey="true"
nullable="false"/>
<field-descriptor id="2"
name="callPrice"
column="CallPrice"
jdbc-type="DOUBLE"
nullable="true"/>
<field-descriptor id="3"
name="expireDate"
column="ExpireDate"
jdbc-type="TIMESTAMP"
nullable="true"/>
<field-descriptor id="4"
name="firstCallDate"
column="FirstCallDate"
jdbc-type="TIMESTAMP"
nullable="true"/>
<field-descriptor id="5"
name="optionType"
column="OptionType"
jdbc-type="VARCHAR"
nullable="true"/>
<field-descriptor id="6"
name="putCallCode"
column="PutCallCode"
jdbc-type="VARCHAR"
nullable="true"/>
</class-descriptor>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>