Hi,
the problem is that FK 'countryid' is used for Region and Country. If OJB doesn't find a Region on update of the main object and auto-update set to 'link' it nullify all FK fields of Region (regionid, countryid) in the main object.
- Set auto-update/auto-delete to 'none' in reference-descriptor "region". In this case you have insert/update/delete Region objects "by hand" - "link by hand".
http://db.apache.org/ojb/docu/guides/basic-technique.html#Link+references
- Use different countryid FK fields -> countryid, countryRegionId. You can declare the new 1:1 FK field 'countryRegionId' as anonymous, then you don't have to change your persistent object class (but you need another column in main object table)
- Avoid the composed PK in Region and make a single PK
regards, Armin
[EMAIL PROTECTED] wrote:
I have a pretty large system running OJB which works well, but now I am trying to internationalize it. I have a problem.
country->region->local is the new general object mapping.
Previously in our last release we just had US and the states, but now the mapping doesn't seem to work.
The problem is for many countries, there are no regions. When I go to update/insert a record without a region, it is now nulling out the country. I believe this is because OJB requires the region to be non-null. I do resolve references before the update, but where regionId is null there can be no region object.
Right now the mapping looks as follow. I don't map local yet as there is no need yet. I would be interested in knowing if this is possible if region is null as well.
I believe what I need is that "NULL" be ok for a key. I need some guidance on what I can do.
Here are the pertinent fields:
--------- ... lots of other fields
<field-descriptor name="countryId" column="countryid" jdbc-type="CHAR" /> <field-descriptor name="regionId" column="regionid" jdbc-type="CHAR" /> <field-descriptor name="localId" column="localid" jdbc-type="CHAR" />
<reference-descriptor name="country" class-ref="com.jb.sp.model.places.CountryVO" auto-retrieve="true" auto-update="link" auto-delete="none" proxy="false"> <foreignkey field-ref="countryId"/> </reference-descriptor>
<reference-descriptor name="region" class-ref="com.jb.sp.model.places.RegionVO" auto-retrieve="true" auto-update="link" auto-delete="none" proxy="false"> <foreignkey field-ref="countryId"/> <foreignkey field-ref="regionId"/> </reference-descriptor>
---------
<class-descriptor class="com.jb.sp.model.places.CountryVO" table="country"> <field-descriptor name="countryId" column="CountryCode" jdbc-type="CHAR" primarykey="true"/> <field-descriptor name="name" column="CountryName" jdbc-type="VARCHAR"/> </class-descriptor>
<class-descriptor class="com.jb.sp.model.places.RegionVO" table="region"> <field-descriptor name="countryId" column="SUCountry" jdbc-type="CHAR" primarykey="true"/> <field-descriptor name="regionId" column="SUCode" jdbc-type="CHAR" primarykey="true"/> <field-descriptor name="name" column="SUName" jdbc-type="VARCHAR"/> </class-descriptor>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
