RE: [ojb-users] mapping multiple objects transparently to a singl e table
Brought to you by:
thma
|
From: Andrew G. <Gee...@do...> - 2002-06-15 15:23:17
|
Thanks for your help.
I'm new at this, so the problem is probably that I'm not specifying the
repository.xml file correctly.
I've included my simple test case below along with a short analysis of what
the problem seems to be.
Thanks
Andrew
=============================
Here's my very simple test case.
table
------
create table test (
id integer not null primary key,
desc varchar(25),
name varchar(25)
);
classes
---------
class Test1 {
private int id;
private String desc;
private Test2 test;
...
}
class Test2 {
private int id;
private String name;
...
}
mappings
------------
<class-descriptor
class="Test1"
table="test"
>
<field-descriptor id="1"
name="id"
column="id"
jdbc-type="INTEGER"
primarykey="true"
/>
<field-descriptor id="2"
name="desc"
column="desc"
jdbc-type="VARCHAR"
/>
<reference-descriptor
name="test2"
class-ref="Test2"
auto-retrieve="true"
auto-update="true"
auto-delete="true"
element-class-ref="Test2"
>
<foreignkey field-id-ref="1"/>
</reference-descriptor>
</class-descriptor>
<class-descriptor
class="Test2"
table="test"
>
<field-descriptor id="1"
name="id"
column="id"
jdbc-type="INTEGER"
primarykey="true"
/>
<field-descriptor id="2"
name="name"
column="name"
jdbc-type="VARCHAR"
/>
</class-descriptor>
main method
----------------
Test1 test1 = new Test1();
test1.setId(1);
test1.setDesc("Test1");
Test2 test2 = new Test2();
test2.setId(1);
test2.setName("Test2");
test1.setTest2(test2);
broker.beginTransaction( );
broker.store( test1 );
broker.commitTransaction( );
Looking at the logging output, the following seems to be happening:
(1) a select statement is executed to check whether the Test2 mapping exists
in the database [it does not]
(2) a select statement is executed to check whether the Test1 mapping exists
in the database [it does not]
(3) an insert statement is executed to map the Test2 values into the
database -- success: a row now exists in the database with an id for object
Test2 (and since it is the same table object Test1).
(4) an *insert* statement is executed to map the Test1 values into the
database -- failure because a row already exists with the id for Test1.
The problem is that step (4) should be a *modify* and not an insert. I
haven't looked at the code yet, but it seems that if step (2) happened after
step (3), it would be determined that step (4) should be a modify and the
problem would be resolved. For example, if the row already exists in the
database and the code is executed, no problem arises because step (4) [and
step (3)] is a modify.
-----Original Message-----
From: Matthew baird [mailto:mat...@ya...]
Sent: Friday, June 14, 2002 5:54 PM
To: Andrew Geery; 'obj...@li...'
Subject: Re: [ojb-users] mapping multiple objects transparently to a single
table
I don't have the answer offhand (I'm probably the most responsible for
multiple objects mapped to a single table right now), but I'll get around to
writing a test case for it soon, unless of course you want to write one for
me. Once the test case is done, I'll look at fixing it. I'll fix it faster
if I have the test case done sooner... hint hint.
m
Andrew Geery <Gee...@do...> wrote:
I was wondering if it is possible to map multiple objects to a single table
transparently.
For example: Object A maps to table T. Object B contains a reference to
object A and also maps to table T. How can I set up the repository.xml file
so that when I call
broker.store( B );
object A is also stored? The problem I am running into is that the database
complains that the id column is specfied more than once in the INSERT
statement
Can this even be done? If it can, a short example would be wonderful.
Thanks
Andrew
_______________________________________________________________
Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -
http://devcon.sprintpcs.com/adp/index.cfm?source=osdntextlink
_______________________________________________
Objectbridge-users mailing list
Obj...@li...
https://lists.sourceforge.net/lists/listinfo/objectbridge-users
_____
Do You Yahoo!?
Sign-up
<http://rd.yahoo.com/welcome/*http://fifaworldcup.yahoo.com/fc/en/spl> for
Video Highlights of 2002 FIFA World Cup
|