Re: Bidirectional 1:1 relations

2006-01-20 Thread Gonçalo Luiz
Hello again,

Kindly forget my last e-mail I was looking to a old page of OJB that
was cached somewere... I think that the
http://db.apache.org/ojb/docu/guides/advanced-technique.html#nested-objects
page wil serve my needs... if it doesn't I will let you know.

Regards,
Gonçalo Luiz

On 1/20/06, Gonçalo Luiz <[EMAIL PROTECTED]> wrote:
> Armin thank you for your reply,
>
> I came to a solution proposed to another OJB mailing poster (Luis
> Cruz) that works with me and suggested that I could invoke the
> getUniqueValue() in the DomainObject super class... its ugly but it
> works fine... and it happens to be a "controlled ugliness".
>
> I was now wondering... is it possible to map an object to two distinct
> columns of the same table? I mean if I have
>
> class Point
> {
> int x;
> int y;
> }
>
> and
> B
> {
> Point p;
> String name;
> }
>
> Can I use the B table to store the points? I was thinking about a
> table with the following schema:
> create table B (name varchar, point_x int, point_y int);
>
> I read the rowreader tutorial but it doesn't seem to fit my needs.
>
> Thank you once again!
>
> Best regards,
> Gonçalo Luiz
>


--
Gonçalo Luiz

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Bidirectional 1:1 relations

2006-01-20 Thread Gonçalo Luiz
Armin thank you for your reply,

I came to a solution proposed to another OJB mailing poster (Luis
Cruz) that works with me and suggested that I could invoke the
getUniqueValue() in the DomainObject super class... its ugly but it
works fine... and it happens to be a "controlled ugliness".

I was now wondering... is it possible to map an object to two distinct
columns of the same table? I mean if I have

class Point
{
int x;
int y;
}

and
B
{
Point p;
String name;
}

Can I use the B table to store the points? I was thinking about a
table with the following schema:
create table B (name varchar, point_x int, point_y int);

I read the rowreader tutorial but it doesn't seem to fit my needs.

Thank you once again!

Best regards,
Gonçalo Luiz

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Bidirectional 1:1 relations

2006-01-16 Thread Armin Waibel

Hi Gonçalo,

Gonçalo Luiz wrote:

Hello,
I've been trying this for hours without minimal success... I have a
A<->B relation the simpliest thing one can imagine. Each class has a
foreign key pointing to each other (a has bKey and b has aKey).
The problem is that when I check the database only one of the
instances have its foreign key value, the other one is zero.

I'm attaching my repository file and my business class that is
persisting the objects. 


The business class was not attached (only the metadata file). Could you 
post the source code again.



I don't really understand why only one side of
the relation have the correct value.
In fact, in the attached files, I have some more occurencies of this
odd problem. However in 1:n bidirectional relationships its seems to
be no problem at all (maybe because there is only one foreign
key).


I think this might be related to the fact that the value of a foreign
key is known only when the pointed instance is persisted... but how
can I fix this behaviour ?



Which version of OJB do you use?



And yes I'm using
auto-retrieve="true"
auto-update="none"
auto-delete="none"
as recomended.


So I assume you are using the ODMG-api - correct?
It's a bidirectional 1:1 relation, thus if A was written to database the 
PK of B is still 'null', thus A get 'null' as FK to B (or vice versa).


You can use OJB's ODMG-Extensions to solve your problem. Here is an 
example using class Shop and ShopDetail with bidirectional 1:1 reference:


CircularTest.Shop s1 = new CircularTest.Shop(name + "_1");
CircularTest.ShopDetail sd = new CircularTest.ShopDetail(name + "_1");
s1.setDetail(sd);
sd.setShop(s1);

TransactionExt tx = (TransactionExt) odmg.newTransaction();
tx.begin();
database.makePersistent(sd);
tx.flush();
database.makePersistent(s1);
tx.commit();

tx.begin();
database.deletePersistent(s1);
tx.flush();
database.deletePersistent(sd);
tx.commit();

regards,
Armin



Please let me know if yoy have any ideas.

Best regards,
--
Gonçalo Luiz









	










name="keyApplication"
column="KEY_APPLICATION"
jdbc-type="INTEGER"

/>


name="keyPerson"
column="KEY_PERSON"
jdbc-type="INTEGER"

/>


name="username"
column="USERNAME"
jdbc-type="VARCHAR"
/>


name="password"
column="PASSWORD"
jdbc-type="VARCHAR"

/>


   
			auto-retrieve="true"

auto-update="none"
auto-delete="none"
name="application"
class-ref="org.goncalo.smsbridge.domain.SmsBridge">




		auto-retrieve="true"

auto-update="none"
auto-delete="none"
name="person"
class-ref="org.goncalo.smsbridge.domain.Person">












name="keyAddressBook"
column="KEY_ADDRESS_BOOK"
jdbc-type="INTEGER"

/>

   
name="keyUser"
column="KEY_USER"
jdbc-type="INTEGER"

/>


name="name"
column="NAME"
jdbc-type="VARCHAR"

/>
   
			auto-retrieve="true"

auto-update="none"
auto-delete="none"
name="addressBook"
class-ref="org.goncalo.smsbridge.domain.addressBook.AddressBook">





		auto-retrieve="true"

auto-update="none"
auto-delete="none"
name="user"
class-ref="org.goncalo.smsbridge.domain.User">







  
  table="ADDRESS_BOOK">




name="keyOwner"
column="KEY_PERSON"
jdbc-type="INTEGER"

/>

			auto-retrieve="true"

auto-update="none"
auto-delete="none"
name="owner"
class-ref="org.goncalo.smsbridge.domain.Person">




 






-
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]



Bidirectional 1:1 relations

2006-01-15 Thread Gonçalo Luiz
Hello,
I've been trying this for hours without minimal success... I have a
A<->B relation the simpliest thing one can imagine. Each class has a
foreign key pointing to each other (a has bKey and b has aKey).
The problem is that when I check the database only one of the
instances have its foreign key value, the other one is zero.

I'm attaching my repository file and my business class that is
persisting the objects. I don't really understand why only one side of
the relation have the correct value.
In fact, in the attached files, I have some more occurencies of this
odd problem. However in 1:n bidirectional relationships its seems to
be no problem at all (maybe because there is only one foreign
key).


I think this might be related to the fact that the value of a foreign
key is known only when the pointed instance is persisted... but how
can I fix this behaviour ?

And yes I'm using
auto-retrieve="true"
auto-update="none"
auto-delete="none"
as recomended.

Please let me know if yoy have any ideas.

Best regards,
--
Gonçalo Luiz



	

	

















   
	















   


   
	











  





	



 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]