You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Steve Clark <sc...@euler.cr.usgs.gov> on 2004/03/25 03:08:54 UTC
Back to square 1
I've been using OJB for over a year now, and when it works, it's a
beautiful thing. Thanks to the team for all you do!
I'm having two problems today which make me feel like a newbie. I'm
hoping somebody can shed some light.
I'm using RC5, Oracle 9i, ODMG, PersistentFieldIntrospectorImpl.
1) Adding to a collection. I have a simple 1:n relationship which
uses an anonymous key. Repository snippet:
<class-descriptor class="Parent">
<field-descriptor name="parentId"
primarykey="true" />
<collection-descriptor name="child"
element-class-ref="Child">
<inverse-foreignkey field-ref="parentId" />
</reference-descriptor>
</class-descriptor>
<class-descriptor class="Child">
<field-descriptor name="parentId"
access="anonymous" />
</class-descriptor>
I've written the following code:
// get parent object, with no children (yet)
Parent parent = <get parent by id>;
Child child = new Child();
tx = fOdmg.newTransaction();
tx.begin();
tx.lock(parent, tx.WRITE);
tx.lock(child, tx.WRITE);
parent.addChild(child);
tx.commit();
Parent.addChild() is defined as:
public void addChild(Child child) {
fChildren.add(child);
}
The commit() throws:
java.sql.SQLException: ORA-01400: cannot insert NULL into ("CHILD"."PARENT_ID")
What am I missing?? Do I have to define the reverse relationship
(Child.parent) in order to get the anonymous key to work?
2) I have a class A with a reference to class B. B is mapped to a
table in a different schema from A; my database user has read-only
access to B's schema. I database.deletePersistent(anA), and OJB
tries to *update* the corresponding B, which I have not changed
(there is no reference from B to A). I have not set auto-anything
anywhere in repository.xml. Why would this happen?
thanks,
-steve
--
Steve Clark
Technology Applications Team
Natural Resources Research Center/USGS
sclark@support.tat.fws.gov
(970)226-9291
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Back to square 1
Posted by Armin Waibel <ar...@apache.org>.
Hi Steve,
I have written an test case without using an anonymous field for 1:n FK
field (recommend anonymous key only for 1:1 relations).
// object gat already exists
CollectibleC child = new CollectibleC(prefix, null, "a new CollectibleC");
tx.begin();
tx.lock(gat, Transaction.WRITE);
tx.lock(child, Transaction.WRITE);
List childs = new ArrayList();
childs.add(child);
gat.setCollectiblesB(childs);
tx.commit();
This works for me with latest from CVS.
regards,
Armin
Steve Clark wrote:
> I've been using OJB for over a year now, and when it works, it's a
> beautiful thing. Thanks to the team for all you do!
>
> I'm having two problems today which make me feel like a newbie. I'm
> hoping somebody can shed some light.
>
> I'm using RC5, Oracle 9i, ODMG, PersistentFieldIntrospectorImpl.
>
> 1) Adding to a collection. I have a simple 1:n relationship which
> uses an anonymous key. Repository snippet:
>
> <class-descriptor class="Parent">
> <field-descriptor name="parentId"
> primarykey="true" />
> <collection-descriptor name="child"
> element-class-ref="Child">
> <inverse-foreignkey field-ref="parentId" />
> </reference-descriptor>
> </class-descriptor>
>
> <class-descriptor class="Child">
> <field-descriptor name="parentId"
> access="anonymous" />
> </class-descriptor>
>
> I've written the following code:
>
> // get parent object, with no children (yet)
> Parent parent = <get parent by id>;
> Child child = new Child();
>
> tx = fOdmg.newTransaction();
> tx.begin();
> tx.lock(parent, tx.WRITE);
> tx.lock(child, tx.WRITE);
> parent.addChild(child);
> tx.commit();
>
> Parent.addChild() is defined as:
> public void addChild(Child child) {
> fChildren.add(child);
> }
>
> The commit() throws:
> java.sql.SQLException: ORA-01400: cannot insert NULL into ("CHILD"."PARENT_ID")
>
> What am I missing?? Do I have to define the reverse relationship
> (Child.parent) in order to get the anonymous key to work?
>
> 2) I have a class A with a reference to class B. B is mapped to a
> table in a different schema from A; my database user has read-only
> access to B's schema. I database.deletePersistent(anA), and OJB
> tries to *update* the corresponding B, which I have not changed
> (there is no reference from B to A). I have not set auto-anything
> anywhere in repository.xml. Why would this happen?
>
> thanks,
> -steve
>
> --
> Steve Clark
> Technology Applications Team
> Natural Resources Research Center/USGS
> sclark@support.tat.fws.gov
> (970)226-9291
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org