I'm having a problem insesrting an object into the database, where the new
record includes a 1:1 reference to another object/record. The excerpted
mapping file is shown below.
In the Java code, I set the portalUser field of UserSurvey with a pre-existing
(and already persistent) instance of PortalUser. When I insert UserSurvey, the
db field for EnduserID is null.
If I call db.setAutoComplete(true) before inserting, then the foreign key
EnduserId field is populated correctly, but a *duplicate* PortalUser is also
inserted.
I could expose "endUserId" as a field of UserSurvey and manually populate it in
my code before insert, but I don't have these get/set methods or field in my
Java class right now. I only have a reference to PortalUser in the Java class
for UserSurvey. Of course, the UserSurvey database table has the foreign key
attribute for EnduserId.
Am I missing something here, or is insertion of pre-existing references not
possible? I'm using SQL Server database, if that makes a difference.
Thanks again,
Dave
<class name="portal.data.UserSurvey" identity="surveyId"
key-generator="IDENTITY">
<map-to table="Portal_UserSurvey" />
<field name="surveyId" type="integer" required="true">
<sql type="integer" name="SurveyId" />
</field>
<field name="surveyDate" type="date" required="true">
<sql type="timestamp" name="SurveyDate" dirty="ignore" />
</field>
<field name="portalUser" type="portal.data.PortalUser">
<sql name="EnduserID" />
</field>
</class>
<class name="portal.data.PortalUser" identity="endUserId"
extends="sentinel.express.EndUserType">
<map-to table="Portal_PortalUser" />
<field name="endUserId" type="integer" required="true">
<sql type="integer" name="EnduserID" />
</field>
<field name="createDate" type="date">
<sql type="timestamp" name="CreateDate" dirty="ignore" />
</field>
</class>
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev