Mapping question

2005-03-03 Thread Georg Müller
Hi,
I have an object User who has 2 addresses, home and work.
User is mapped to a table user (no problem here).
Both home and work address are mapped to a table address.
This table has a composite primary key: login and type
 - login from table user as a foreign key
 - type is a string (or enum) home and work
I have tried the following without success:
in User description:
reference-descriptor
  name=homeAddress
  class-ref=Address
  auto-update=true
  auto-delete=true
  attribute attribute-name=type attribute-value=heimat/
  foreignkey field-ref=login /
/reference-descriptor
and in Address description:
field-descriptor
  name=login
  column=login
  primarykey=true /
field-descriptor
  name=type
  column=type
  primarykey=true /
Is it possible to make it run anyhow?
Regards,
Georg
P.S.: Please CC me
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Mapping question

2005-03-03 Thread Georg Müller
Sorry for that second posting. I sent this before I subscribed to the 
list, so I thought it will not be posted (now, with a latency of nearly 
one day)

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


RE: Mapping question

2005-03-03 Thread Günther Wieser
hi,

as far as i understand this, you try to differentiate by the value of
adress.type whether an adress is a home wor work adress?
well, i have no solution for that, but i tried it here with a similair data
structur, and it didn't work either.
to be honest i'm not sure if this is the intended use for attribute in
collection-descriptor or reference-descriptor, because i didn't find
anything in the docs. all i found was an example in the ojb test cases in
repository_junit.xml, but the corresponding source code didn't tell me
anything i could understand.

so, long speach, short meaning: i'm also interested in a solution for that!

kr,
guenther


-Original Message-
From: Georg Müller [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 02, 2005 9:24 PM
To: ojb-user@db.apache.org
Subject: Mapping question

Hi,

I have an object User who has 2 addresses, home and work.

User is mapped to a table user (no problem here).

Both home and work address are mapped to a table address.
This table has a composite primary key: login and type
  - login from table user as a foreign key
  - type is a string (or enum) home and work

I have tried the following without success:

in User description:

reference-descriptor
   name=homeAddress
   class-ref=Address
   auto-update=true
   auto-delete=true
   attribute attribute-name=type attribute-value=heimat/
   foreignkey field-ref=login /
/reference-descriptor


and in Address description:

field-descriptor
   name=login
   column=login
   primarykey=true /

field-descriptor
   name=type
   column=type
   primarykey=true /


Is it possible to make it run anyhow?

Regards,
Georg

P.S.: Please CC me

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



Re: Mapping question

2005-03-03 Thread Armin Waibel
Hi,
not sure that I understand the problem.
Each User has two Address attributes ('home' and 'work'), both are of 
the same type 'Address' (both 1:1 references), you don't use extension 
classes AddressHome and AddressWork objects. Address use a composite PK 
('login' and 'type').

In this case each reference has to use a composite FK key too.
in User (assume the 'login' datatype is INTEGER and User use an 
autoincrement PK, only show mapping for the 'home' reference, 'work' 
will be the same):

You need a FK field for each PK value of the referenced object, if you 
use 'anonymous' fields, you don't need a real fields in your 
persistent object class (User) - more info see docs.
http://db.apache.org/ojb/docu/guides/advanced-technique.html#How+do+

field-descriptor
 name=fkLoginHome
 column=FK_LOGIN_HOME
 jdbc-type=INTEGER
access=anonymous
/
field-descriptor
 name=fkTypeHome
 column=FK_TYPE_HOME
 jdbc-type=VARCHAR
access=anonymous
/
reference-descriptor
   name=homeAddress
   class-ref=Address
   auto-retrieve=true
   auto-update=true
   auto-delete=true
   foreignkey field-ref=fkLoginHome /
   foreignkey field-ref=fkTypeHome /
/reference-descriptor
In Address you use the composite PK and both attributes has to be set by 
hand (no PK auto-generation was used) and the 'login' field is a FK from 
User table. This will make things complicated, because on insert OJB 
will first store the 1:1 references, but in your case we need the 
'login' PK first. So we need a workaround when insert User objects:

broker.beginTransaction();
User user = new User();
broker.store(user);
// now the PK ('login' field in User) is specified
Address home = new Address();
home.setLogin(user.getLogin());
home.setType(home);
user.setHome(home);
//
broker.store(user);
broker.commitTransaction();
Things will be easier when you use an single autoincremented PK field in 
Address. In this case all will be handled by OJB and you only need 
single FK field-descriptor in User:

broker.beginTransaction();
User user = new User();
Address home = new Address();
home.setType(home);
user.setHome(home);
broker.store(user);
broker.commitTransaction();
regards,
Armin
Günther Wieser wrote:
hi,
as far as i understand this, you try to differentiate by the value of
adress.type whether an adress is a home wor work adress?
well, i have no solution for that, but i tried it here with a similair data
structur, and it didn't work either.
to be honest i'm not sure if this is the intended use for attribute in
collection-descriptor or reference-descriptor, because i didn't find
anything in the docs. all i found was an example in the ojb test cases in
repository_junit.xml, but the corresponding source code didn't tell me
anything i could understand.
so, long speach, short meaning: i'm also interested in a solution for that!
kr,
guenther
-Original Message-
From: Georg Müller [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, March 02, 2005 9:24 PM
To: ojb-user@db.apache.org
Subject: Mapping question

Hi,
I have an object User who has 2 addresses, home and work.
User is mapped to a table user (no problem here).
Both home and work address are mapped to a table address.
This table has a composite primary key: login and type
  - login from table user as a foreign key
  - type is a string (or enum) home and work
I have tried the following without success:
in User description:
reference-descriptor
   name=homeAddress
   class-ref=Address
   auto-update=true
   auto-delete=true
   attribute attribute-name=type attribute-value=heimat/
   foreignkey field-ref=login /
/reference-descriptor
and in Address description:
field-descriptor
   name=login
   column=login
   primarykey=true /
field-descriptor
   name=type
   column=type
   primarykey=true /
Is it possible to make it run anyhow?
Regards,
Georg
P.S.: Please CC me
-
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]

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


Re: Mapping question

2005-03-03 Thread Thomas Dudziak
As far as I understand he wants to use a reference that refers to a
class with a compound primarykey, where one of the foreignkey values
is fixed:

reference-descriptor name=homeAddress
  class-ref=Address
  auto-update=true
  auto-delete=true
  foreignkey field-ref=login /
  foreignkey expression=heimat /
  !-- the second part of the fk relating to pk part 'type', is fixed
to heimat --
/reference-descriptor

That would actually be a neat feature to have IMO ?!

Tom

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



Re: Mapping question

2005-03-03 Thread Georg Müller
Thomas Dudziak wrote:
As far as I understand he wants to use a reference that refers to a
class with a compound primarykey, where one of the foreignkey values
is fixed:
reference-descriptor name=homeAddress
  class-ref=Address
  auto-update=true
  auto-delete=true
  foreignkey field-ref=login /
  foreignkey expression=heimat /
  !-- the second part of the fk relating to pk part 'type', is fixed
to heimat --
/reference-descriptor
Yes, that is what I am searching for.
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Mapping question

2005-03-03 Thread Günther Wieser
i tried to change my code to using extends, it works perfect for me, and
from an object oriented design view, this is perfect!

what i did (if i apply the things i did to georgs problem):

- create an abstract class Address that has all attributes in it
- derive both classes HomeAddress and WorkAddress from Address
- setup the constructor of both classes as described in
 
http://db.apache.org/ojb/docu/guides/advanced-technique.html#Extents+and+Pol
ymorphism
- setup the repository.xml as described in the chapter
 
http://db.apache.org/ojb/docu/guides/advanced-technique.html#Mapping+All+Cla
sses+on+the+Same+Table

this works perfect for me and is much cleaner (but of course works only if
you can change your db layout).
if you can't change the layout, one possible solution is described in
 
http://db.apache.org/ojb/docu/guides/advanced-technique.html#Mapping+All+Cla
sses+on+the+Same+Table
when showing how to implement your own ClassDescriptor. cool stuff!

kr,
guenther


-Original Message-
From: Georg Müller [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 03, 2005 11:33 PM
To: OJB Users List
Subject: Re: Mapping question

Thomas Dudziak wrote:
 As far as I understand he wants to use a reference that refers to a 
 class with a compound primarykey, where one of the foreignkey values 
 is fixed:
 
 reference-descriptor name=homeAddress
   class-ref=Address
   auto-update=true
   auto-delete=true
   foreignkey field-ref=login /
   foreignkey expression=heimat /
   !-- the second part of the fk relating to pk part 'type', is fixed 
 to heimat -- /reference-descriptor
 

Yes, that is what I am searching for.

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



Re: Mapping question

2005-03-03 Thread Georg Müller
I now have a running version, but the way Thomas proposed would be much 
nicer.

I have added a collection descriptor
collection-descriptor
  name=addresses
  element-class-ref=Adress
  auto-update=true
  auto-delete=true
  inverse-foreignkey field-ref=login/
/collection-descriptor
and he returns both addresses.
I tried to modify my getters and setters for addresses to set 
homeAddress and workAddress, but I tested this and noticed that they are 
not invoked (why should they? (*grml*))

So I added a function assignAddresses(), which is invoked by the DAO 
getUser method.

public void addressAssignment() {

  Iterator i = this.adresses.iterator();
  while (i.hasNext()) {
Adress address = (Address) i.next();
if (home.equals(adress.getType()))
  this.homeAddress = address;
if (work.equals(adress.getType()))
  this.workAddress = address;
  }
}
Now I have to take care that every setHomeAddress also modifies the 
collection (because I don't think that getAddresses() is invoked by ojb 
either ;) )

May be I implement a query costomizer who filters the addresses like 
described in the advanced mapping tutorial:

collection-descriptor
  name=homeAddressCollection
  element-class-ref=Address
  auto-update=true
  auto-delete=true
  inverse-foreignkey field-ref=login/
  query-customizer
   class=AddressQueryCustomizer
attribute attribute-name=type attribute-value=home /
  /query-customizer
/collection-descriptor
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Mapping question

2005-03-02 Thread Georg Mller
Hi,
I have an object User who has 2 addresses, one for home and one for work.
User is mapped to a table user (no problem here).
Both home and work address are mapped to a table address.
This table has a composite primary key: login and type
 - login from table user as a foreign key
 - type is a string (or enum) home and work
I have tried the following without success:
in User description:
reference-descriptor
  name=homeAddress
  class-ref=Address
  auto-update=true
  auto-delete=true
  attribute attribute-name=type attribute-value=home/
  foreignkey field-ref=login /
/reference-descriptor
and in Address description:
field-descriptor
  name=login
  column=login
  primarykey=true /
field-descriptor
  name=type
  column=type
  primarykey=true /
Is it possible to make it run anyhow?
Regards,
Georg
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Mapping question

2004-06-03 Thread Daniel Perry
I'm not sure how OJB does it, but that would either mean a lot of queries,
or an awful lot of outer joins!

I wouldn't of thought there was a way to tell OJB to pick tables based on
their foreign id. Generally you use references to exact types, or supertypes
that are extended by a few classes.

I think the correct way to deal with this is by using extents.  I say this
because in the java class that references another object, you will have to
use the same approach.

Lets say you have a classes A,B,C,D, etc

If in A it has a reference to myFriend: as you don't know the type of
myFriend (could be A, B, C, D, etc), you can only refer to something that
all these classes extend (or implement).

So,

class A extends BaseClass {
BaseClass myFriend;
}

and all the classes muse extend BaseClass.

I'm not sure what it is you're trying to map, but I've never come across a
case where you always need to refer to any class.

You could use extents like this, and use this where you need to reference
*any* object, but you could still reference a type directly where you know
what it will be.

So if you know that myFriendFKID will always be a B:

class A extends BaseClass {
B myFriend;
}

You can just use a reference descriptor in the repository referencing the
type B, not the BaseClass extent.

Hope this clarifies things,

Daniel.



 -Original Message-
 From: news [mailto:[EMAIL PROTECTED] Behalf Of Sebastian
 Sent: 02 June 2004 17:47
 To: [EMAIL PROTECTED]
 Subject: Re: Mapping question


 Hi Daniel,

 I had a look at the extents now. I think this will basically work. The
 problem I see is, that the database has 110 tables and all are using a
 globally generated OID. In my basic class I would have to list all other
 classes as extents of this one.

 What does this mean for the performance of OJB? will OJB now query all
 110 tables to find the right object?

 Since I know quite easily based on the first 3 letters of the OID what
 type it is, can I somehow tell that OJB as a hint to search the
 right table?

 Sebastian

 Daniel Perry wrote:

  What about using an extent and having both types extend it.  It
 would pick
  the right class based on whichever table has an item with that
 primary key.
 
  Daniel.
 
 
 -Original Message-
 From: news [mailto:[EMAIL PROTECTED] Behalf Of Sebastian
 Sent: 02 June 2004 17:07
 To: [EMAIL PROTECTED]
 Subject: Re: Mapping question
 
 
 To simplify my question:
 
 I have a table containing a foreign key column and the foreign key of a
 row points to different tables based on the first three letters of the
 foreign key. E.g. when it starts with art then it points to a record
 in the article table. When it starts with cat then it points to a
 category table.
 
 This means OJB should based on the first three letters of the foreign
 key know what kind of object to reference.
 
 What kind of custom mapper or converter or whatever do I have to write.
 
 Thanks,
 Sebastian
 
 
 Sebastian wrote:
 
 Hi,
 I'm trying to map some tables with OJBs but don't know how to express
 their relation. Maybe someone can give me a hint.
 
 I have three tables:
 articles with OID as primary key
 categories with OID as primary key
 custom_fields with OID as primary key, OID_FK as foreign key
 
 OID is generated uniquely over all tables in a format: first 3 letters
 of the table name plus a incrementing value. E.g.
 cat01,art02,art03,cus04.
 
 An article as well as a category can have a custom field that is stored
 in the custom_fields table, the OID_FK is the OID of the
 
 related article
 
 or category. The first three letters of OID indicate the object type
 article or category.
 
 How do I have to configure the repository.xml so that always the right

 object (a category or an article) is referenced by an
 
 customField object?
 
 Thanks in advance,
 Sebastian


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



Re: Mapping question

2004-06-02 Thread Sebastian
To simplify my question:
I have a table containing a foreign key column and the foreign key of a 
row points to different tables based on the first three letters of the 
foreign key. E.g. when it starts with art then it points to a record 
in the article table. When it starts with cat then it points to a 
category table.

This means OJB should based on the first three letters of the foreign 
key know what kind of object to reference.

What kind of custom mapper or converter or whatever do I have to write.
Thanks,
Sebastian
Sebastian wrote:
Hi,
I'm trying to map some tables with OJBs but don't know how to express 
their relation. Maybe someone can give me a hint.

I have three tables:
articles with OID as primary key
categories with OID as primary key
custom_fields with OID as primary key, OID_FK as foreign key
OID is generated uniquely over all tables in a format: first 3 letters 
of the table name plus a incrementing value. E.g. 
cat01,art02,art03,cus04.

An article as well as a category can have a custom field that is stored 
in the custom_fields table, the OID_FK is the OID of the related article 
or category. The first three letters of OID indicate the object type 
article or category.

How do I have to configure the repository.xml so that always the right 
object (a category or an article) is referenced by an customField object?

Thanks in advance,
Sebastian

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


RE: Mapping question

2004-06-02 Thread Daniel Perry
What about using an extent and having both types extend it.  It would pick
the right class based on whichever table has an item with that primary key.

Daniel.

 -Original Message-
 From: news [mailto:[EMAIL PROTECTED] Behalf Of Sebastian
 Sent: 02 June 2004 17:07
 To: [EMAIL PROTECTED]
 Subject: Re: Mapping question


 To simplify my question:

 I have a table containing a foreign key column and the foreign key of a
 row points to different tables based on the first three letters of the
 foreign key. E.g. when it starts with art then it points to a record
 in the article table. When it starts with cat then it points to a
 category table.

 This means OJB should based on the first three letters of the foreign
 key know what kind of object to reference.

 What kind of custom mapper or converter or whatever do I have to write.

 Thanks,
 Sebastian


 Sebastian wrote:
  Hi,
  I'm trying to map some tables with OJBs but don't know how to express
  their relation. Maybe someone can give me a hint.
 
  I have three tables:
  articles with OID as primary key
  categories with OID as primary key
  custom_fields with OID as primary key, OID_FK as foreign key
 
  OID is generated uniquely over all tables in a format: first 3 letters
  of the table name plus a incrementing value. E.g.
  cat01,art02,art03,cus04.
 
  An article as well as a category can have a custom field that is stored
  in the custom_fields table, the OID_FK is the OID of the
 related article
  or category. The first three letters of OID indicate the object type
  article or category.
 
  How do I have to configure the repository.xml so that always the right
  object (a category or an article) is referenced by an
 customField object?
 
  Thanks in advance,
  Sebastian


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



Re: Mapping question

2004-06-02 Thread Sebastian
Hi Daniel,
I had a look at the extents now. I think this will basically work. The 
problem I see is, that the database has 110 tables and all are using a 
globally generated OID. In my basic class I would have to list all other 
classes as extents of this one.

What does this mean for the performance of OJB? will OJB now query all 
110 tables to find the right object?

Since I know quite easily based on the first 3 letters of the OID what 
type it is, can I somehow tell that OJB as a hint to search the right table?

Sebastian
Daniel Perry wrote:
What about using an extent and having both types extend it.  It would pick
the right class based on whichever table has an item with that primary key.
Daniel.

-Original Message-
From: news [mailto:[EMAIL PROTECTED] Behalf Of Sebastian
Sent: 02 June 2004 17:07
To: [EMAIL PROTECTED]
Subject: Re: Mapping question
To simplify my question:
I have a table containing a foreign key column and the foreign key of a
row points to different tables based on the first three letters of the
foreign key. E.g. when it starts with art then it points to a record
in the article table. When it starts with cat then it points to a
category table.
This means OJB should based on the first three letters of the foreign
key know what kind of object to reference.
What kind of custom mapper or converter or whatever do I have to write.
Thanks,
Sebastian
Sebastian wrote:
Hi,
I'm trying to map some tables with OJBs but don't know how to express
their relation. Maybe someone can give me a hint.
I have three tables:
articles with OID as primary key
categories with OID as primary key
custom_fields with OID as primary key, OID_FK as foreign key
OID is generated uniquely over all tables in a format: first 3 letters
of the table name plus a incrementing value. E.g.
cat01,art02,art03,cus04.
An article as well as a category can have a custom field that is stored
in the custom_fields table, the OID_FK is the OID of the
related article
or category. The first three letters of OID indicate the object type
article or category.
How do I have to configure the repository.xml so that always the right
object (a category or an article) is referenced by an
customField object?
Thanks in advance,
Sebastian

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


Mapping question

2004-02-16 Thread ftanare
Hello, 
I want to know if it's possible (and how could I do that) to map this kind of 
relation in OJB. 

Table A
idA
otherFields


Table B
idB
otherFields

Table C
idC
foreignId
type
otherFields

Relation : C - A 1:n 
   C - B 1:n

example :
A
a1 ...
a2 ...

B
b1 ...
b2 ...

C
c1 b1   typeB ...
c2 a1   typeA ...
c3 b2   typeB ...


In my dream I will have in C object both a collection of A object and a 
collection of B object.
Thanks
Florent


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



Re: Mapping question

2004-02-16 Thread BIRGITTA . MOEHRING





Hello Florent,

I understand this as a question about the typeB collection or the typeA
collection exclusively in the C instance?
Then you can't even model this in UML (or so I think), so I don't think you
can in OJB.

The only workaround I know without having two collections in C is a
relation to the class Object (or another parent of A as well as parent of
B), but actually I have huge problems with OJB in determining which is the
real child class with a relation to the parent class.

What is so bad about having two collections in C anyway? In the setter
method you cold restrict on having only one collection filled.

regards,
Birgitta

Re: Mapping question

2004-02-16 Thread ftanare
My english is not good ;-)
What I want is in C object 2 collections one with typeA Object and one with 
typeB Object. My question is how to do a mapping with OJB that can make this 
kind of switch on type field.
In other word when I load A objects collection of a C object the query is :
SELECT AFields ... FROM A, C WHERE C.id=? AND C.foreignId = A.idA AND 
C.type=typeA
And for B objects collection :
SELECT BFields ... FROM B, C WHERE C.id=? AND C.foreignId = B.idB AND 
C.type=typeB.

regards,
Florent

ps :
the relation to map was :
Table A
idA
otherFields


Table B
idB
otherFields

Table C
idC
foreignId
type
otherFields

Relation : C - A 1:n 
   C - B 1:n

example :
A
a1 ...
a2 ...

B
b1 ...
b2 ...

C
c1 b1   typeB ...
c2 a1   typeA ...
c3 b2   typeB ...



Surlignage [EMAIL PROTECTED]:

 
 
 
 
 
 Hello Florent,
 
 I understand this as a question about the typeB collection or the typeA
 collection exclusively in the C instance?
 Then you can't even model this in UML (or so I think), so I don't think you
 can in OJB.
 
 The only workaround I know without having two collections in C is a
 relation to the class Object (or another parent of A as well as parent of
 B), but actually I have huge problems with OJB in determining which is the
 real child class with a relation to the parent class.
 
 What is so bad about having two collections in C anyway? In the setter
 method you cold restrict on having only one collection filled.
 
 regards,
 Birgitta



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



Re: Mapping question

2004-02-16 Thread BIRGITTA . MOEHRING




Hello again,

If you want C.foreignId = A.idA then the 1:n - relation between C and A
is the other way round: C would be the n-class.
But if you simply want C having two collections as attributes, it is
described in tutorial 3, mapping 1:n relations.
Was that the answer?

regards,
Birgitta

RE: Simple 1:n mapping question

2004-01-30 Thread Brendan Richards
Rick,


Using the broker api, I've just built a very similar relationship and
got it working. If I paste in my code you should be able to just change
the class names to match your app. 

I have a one-to-many relationship between a Contact object and an object
called SimpleProperty. SimplePropery holds a foreign key pointing back
to a contact, so one Contact can hold many SimplePropertys but a
SimplePropery always belongs to one Contact. 

First setup your mapping XML so that the contact object knows how to
populate its collection. (I'm using MS SQL so the key type is varchar in
my code). The two classes are simple Java Beans.
 

class-descriptor
  class=com.designuk.crm.Contact
  table=contacts
   
  field-descriptor
 name=guid
 column=guid
 jdbc-type=VARCHAR
 primarykey=true
 autoincrement=true
 nullable=false
  /

... some other properties ...

collection-descriptor
 name=simpleProperties
 element-class-ref=com.designuk.crm.SimpleProperty
  
 inverse-foreignkey field-ref=ownerGuid/
  /collection-descriptor 

  
   /class-descriptor


with ownerGuid being the foreign key in simpleProperties

class-descriptor
  class=com.designuk.crm.SimpleProperty
  table=simpleProperties
   
  field-descriptor
 name=guid
 column=guid
 jdbc-type=VARCHAR
 primarykey=true
 autoincrement=true
 nullable=false
  /

... other properties ...

  field-descriptor
 name=ownerGuid
 column=ownerGuid
 nullable=false
 jdbc-type=VARCHAR
  /
/class-descriptor



This mapping setup means that every time you query the database via one
of the APIs to get a Contact, it will automatically populate the correct
SimpleProperty objects into contact's simpleProperties collection.
(Pretty cool...)


To query across these two objects, you can build criteria. For example
to get all the Contacts that have a SimplePropery with
name=nationality AND value=British (name and value being a fields in
the simpleProperties table):

// get persistence broker
PersistenceBroker broker =
PersistenceBrokerFactory.defaultPersistenceBroker();


// build two criteria on simpleProperties table

Criteria c1 = new Criteria();
c1.addEqualTo(simpleProperties.name, nationality);
Criteria c2 = new Criteria();
c2.addEqualTo(simpleProperties.value, British);

// AND the two criteria together
c1.addAndCriteria(c2);

Query jquery = QueryFactory.newQuery(Contact.class, c1);

Collection jresults = broker.getCollectionByQuery(jquery);


This gives you a collection of Contact objects matching your query, each
one with the appropriate number of SimpleProperty objects loaded into
its Collection.

Hope this helps, Please correct me if I've made any erroneous
assumptions. 


Brendan.


-Original Message-
From: Rick Banerjee [mailto:[EMAIL PROTECTED] 
Sent: 30 January 2004 06:22
To: [EMAIL PROTECTED]
Subject: Simple 1:n mapping question

Hi Everybody,

I have a 1:n relationship between 
Person  Application tables.

I have Person  Application valueobjects
representing the tables respectively.

I want to search on the join of these
tables with criteria pertaining to both
tables. 

In the Person value object I have a
Collection allApplications to hold applications
for a Person.

Is there any way to get a limited set of Applications
into the allApplications collection?

Regards

Rick


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



Simple 1:n mapping question

2004-01-29 Thread Rick Banerjee
Hi Everybody,

I have a 1:n relationship between 
Person  Application tables.

I have Person  Application valueobjects
representing the tables respectively.

I want to search on the join of these
tables with criteria pertaining to both
tables. 

In the Person value object I have a
Collection allApplications to hold applications
for a Person.

Is there any way to get a limited set of Applications
into the allApplications collection?

Regards

Rick


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



RE: Mapping Question

2004-01-04 Thread Coup, Robert Muir
Hi Patrick.

Is the field doc_id in download_pal_model actually meant to be model_id?
Otherwise I am a touch confused :)

Also, I assume you've checked out the advanced O/R mapping stuff at
http://db.apache.org/ojb/tutorial3.html - if not, do it now!

Idea #1:
  For download - model
class-descriptor class=download table=t_download
  ... Field Descriptors ...

  collection-descriptor name=models
element-class-ref=pal_model
indirection-table=t_download_pal_model

fk-pointing-to-this-class column=download_id/
fk-pointing-to-element-class column=model_id/
  /collection-descriptor
/class-descriptor
  And going from model - download...
class-descriptor class=model table=t_model
  ... Field Descriptors ...

  collection-descriptor name=downloads
element-class-ref=download
indirection-table=t_download_pal_model

fk-pointing-to-this-class column=model_id/
fk-pointing-to-element-class column=download_id/
  /collection-descriptor
/class-descriptor

Okay, that's a simple non-decomposed M:N and you probably know that
already ... That doesn't really help with the single-collection issue at
all.


Idea #2:
How about:
class-descriptor class=SupportItemI
  extent-class class-ref=Document/
  extent-class class-ref=Download/
/class-descriptor

class-descriptor class=pal_model table=t_pal_model
  ... Field Descriptors ...
  collection descriptor name=collectionOfSupportItemIs
element-class-ref=SupportItemI
indirection-table=t_pal_model_supportitems

fk-pointing-to-this-class column=model_id/
fk-pointing-to-element-class column=SupportItemID/
  /collection-descriptor
/class-descriptor 

class-descriptor class=download table=t_download
  ... Field Descriptors ...
  collection-descriptor name=models
element-class-ref=pal_model
indirection-table=t_download_pal_model

fk-pointing-to-this-class column=SupportItemID/
fk-pointing-to-element-class column=model_id/
  /collection-descriptor
/class-descriptor

You should be able to keep your object design the same and just modify
the tables a bit so there is one table for both relations... Still
non-decomposed :)

#3:
Implement pal_model_download and pal_model_document as classes,
extending a common class (ModelContents). Then ...

class-descriptor class=ModelContents
  extent-class class-ref=pal_model_download/
  extent-class class-ref=pal_model_document/
/class-descriptor

class-descriptor class=pal_model table=t_pal_model
  ... Field Descriptors ...
  collection descriptor name=collectionOfSupportItemIs
element-class-ref=ModelContents

inverse-foreignkey field-ref=model_id/
  /collection-descriptor
/class-descriptor 

class-descriptor class=download table=t_download
  ... Field Descriptors ...
  collection-descriptor name=Models
element-class-ref=pal_model_download

inverse-foreignkey field-ref=download_id/
  /collection-descriptor
/class-descriptor

class-descriptor class=pal_model_download
table=t_pal_model_download
  field-descriptor name=model_id ... /
  field-descriptor name=download_id ... /
  reference-descriptor name=download
class-ref=download

foreignkey field-ref=download_id/
  /reference-descriptor
  reference-descriptor name=model
class-ref=model

foreignkey field-ref=model_id/
  /reference-descriptor
/class-descriptor

This will make the object model a bit harder, since
model.collectionOfSupportItemIs will return ModelContent objects, not
actual Downloads/Documents (i.e decomposed M:N) but you can keep the
existing table stuff.



Others may have better ideas :)

Good Luck,

Rob :)



-Original Message-
From: Patrick Scheuerer [mailto:[EMAIL PROTECTED] 
Sent: Friday, 2 January 2004 2:56 p.m.
To: OJB Users List
Subject: Mapping Question


Hi,

Please see the attached image of my data model for reference (I'm sorry
for the 
attachment but it's kind of complicated to describe the scenario
otherwise. A 
picture says more than a thousand words :-) ).

How do I map the relationship between pal_model - download and pal_model
- document? The corresponding value objects (DownloadVO and DocumentVO)
both implement the 
Interface SupportItemI.
My PalModelVO has a collection which holds all the SupportItemIs for a
PalModelVO.

How can I map a collection that gets it's data from two m-n
relationships? Can I 
specify two indirection tables? Do i have to change my data model?

Any comments and suggestions are welcome.

I wish everybody a peaceful, prosperous and happy new year! Patrick


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



Mapping Question

2004-01-01 Thread Patrick Scheuerer
Hi,

Please see the attached image of my data model for reference (I'm sorry for the 
attachment but it's kind of complicated to describe the scenario otherwise. A 
picture says more than a thousand words :-) ).

How do I map the relationship between pal_model - download and pal_model - document?
The corresponding value objects (DownloadVO and DocumentVO) both implement the 
Interface SupportItemI.
My PalModelVO has a collection which holds all the SupportItemIs for a PalModelVO.

How can I map a collection that gets it's data from two m-n relationships? Can I 
specify two indirection tables? Do i have to change my data model?

Any comments and suggestions are welcome.

I wish everybody a peaceful, prosperous and happy new year!
Patrick
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Re: Mapping Question

2004-01-01 Thread Patrick Scheuerer
ooops, I guess attachments are not allowed in this mailing list.

here's a link to the picture:
http://homepage.hispeed.ch/tabalooga/datamodel.jpg
the same problem of course also exists for the keyword table.

Thank you, Patrick

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


RE: Mapping question

2003-12-01 Thread Norbert . Woegerbauer
Hello Eric,
the descriptor as example:

class-descriptor 
  class=at.gv.bmi.ClassA
  table=TableA
  
  field-descriptor 
 name=fieldA
 column=A
 jdbc-type=CHAR
 primarykey=true
  /
  field-descriptor 
 name=fieldB
 column=B
 jdbc-type=CHAR
  /
  collection-descriptor
 name=joinAB
 element-class-ref=at.gv.bmi.ClassB
  
 inverse-foreignkey field-ref=fieldY/
  /collection-descriptor
/class-descriptor


class-descriptor 
  class=at.gv.bmi.ClassB
  table=TableB
  
  field-descriptor 
 name=fieldX
 column=X
 jdbc-type=CHAR
 primarykey=true
  /
  field-descriptor 
 name=fieldY
 column=Y
 jdbc-type=CHAR
  /
  field-descriptor 
 name=fieldZ
 column=Z
 jdbc-type=CHAR
  /
/class-descriptor

The join has to be made from ClassA:B to ClassB:Y, ie the where condition
has to be 
where A0.B = A1.Y instead of A0.A = A1.Y
What do I have to do to get this join?

Thanks,
Norbert.

-Original Message-
From: eric barbe [mailto:[EMAIL PROTECTED]
Sent: Freitag, 28. November 2003 15:08
To: OJB Users List
Subject: RE: Mapping question


Hi,

I don't really understand you're pb. ;o(
Is it : any field from my class A can be THE foreign key (mykey in this
case) from my class B ?

Regards

Éric

-Message d'origine-
De : [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Envoyé : jeudi 27 novembre 2003 17:49
À : [EMAIL PROTECTED]
Objet : RE: Mapping question


Thanks, I defined it like that, but:

If A is 1 and B is n.
In A class descriptor write :

collection-descriptor name=relation_name_in_A_class
element-class-ref=url.B
   inverse-foreignkey field-ref=mykey/
/collection-descriptor

And in B class descriptor write this

field-descriptor name=mykey column=mycolumn jdbc-type=INTEGER/
Here mykey is the foreignkey but not a primary key !

OJB generates statements where mykey points to the pk of class A. The
generated join looks like: A.pk = B.mykey
We need: A.anyField = B.mykey
In fact I think we've a m:n mapping without intermediary table...
What can we do (the database model cannot be changed)?
Is there a possibility to add to the collection-descriptor something like
foreignkey field-ref=anyField/ similar to the inverse-foreignkey/
element?

Thanks again.

-Message d'origine-
De : [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Envoyé : jeudi 27 novembre 2003 16:57
À : [EMAIL PROTECTED]
Objet : Mapping question


Hi,

I've got a 1:n mapping from table A to table B. But the foreign key field of
table A is not it's primary key. I can't find how to tell OJB to use another
field to join table B.
Thanks for help, Norbert.


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


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

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



RE: Mapping question

2003-11-28 Thread eric barbe
Hi,

I don't really understand you're pb. ;o(
Is it : any field from my class A can be THE foreign key (mykey in this
case) from my class B ?

Regards

Éric

-Message d'origine-
De : [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Envoyé : jeudi 27 novembre 2003 17:49
À : [EMAIL PROTECTED]
Objet : RE: Mapping question


Thanks, I defined it like that, but:

If A is 1 and B is n.
In A class descriptor write :

collection-descriptor name=relation_name_in_A_class
element-class-ref=url.B
   inverse-foreignkey field-ref=mykey/
/collection-descriptor

And in B class descriptor write this

field-descriptor name=mykey column=mycolumn jdbc-type=INTEGER/
Here mykey is the foreignkey but not a primary key !

OJB generates statements where mykey points to the pk of class A. The
generated join looks like: A.pk = B.mykey
We need: A.anyField = B.mykey
In fact I think we've a m:n mapping without intermediary table...
What can we do (the database model cannot be changed)?
Is there a possibility to add to the collection-descriptor something like
foreignkey field-ref=anyField/ similar to the inverse-foreignkey/
element?

Thanks again.

-Message d'origine-
De : [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Envoyé : jeudi 27 novembre 2003 16:57
À : [EMAIL PROTECTED]
Objet : Mapping question


Hi,

I've got a 1:n mapping from table A to table B. But the foreign key field of
table A is not it's primary key. I can't find how to tell OJB to use another
field to join table B.
Thanks for help, Norbert.


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


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



Mapping question

2003-11-27 Thread Norbert . Woegerbauer
Hi,

I've got a 1:n mapping from table A to table B. But the foreign key field of
table A is not it's primary key. I can't find how to tell OJB to use another
field to join table B.
Thanks for help, Norbert.


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



RE: Mapping question

2003-11-27 Thread Norbert . Woegerbauer
Thanks, I defined it like that, but:

If A is 1 and B is n.
In A class descriptor write :

collection-descriptor name=relation_name_in_A_class
element-class-ref=url.B
   inverse-foreignkey field-ref=mykey/
/collection-descriptor

And in B class descriptor write this

field-descriptor name=mykey column=mycolumn jdbc-type=INTEGER/
Here mykey is the foreignkey but not a primary key !

OJB generates statements where mykey points to the pk of class A. The
generated join looks like: A.pk = B.mykey
We need: A.anyField = B.mykey
In fact I think we've a m:n mapping without intermediary table...
What can we do (the database model cannot be changed)?
Is there a possibility to add to the collection-descriptor something like
foreignkey field-ref=anyField/ similar to the inverse-foreignkey/
element?

Thanks again.

-Message d'origine-
De : [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Envoyé : jeudi 27 novembre 2003 16:57
À : [EMAIL PROTECTED]
Objet : Mapping question


Hi,

I've got a 1:n mapping from table A to table B. But the foreign key field of
table A is not it's primary key. I can't find how to tell OJB to use another
field to join table B.
Thanks for help, Norbert.


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


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



Re: o/r mapping question

2003-11-03 Thread sclark
How about this:

public class Person {
private AddressGroup fAddressGroup;

...

/** Convenience method: create AddressGroup and set addresses indirectly */
public void setAddresses(List addresses) {
fAddressGroup = new AddressGroup(addresses);
}

/** Convenience method: retrieve addresses from my AddressGroup */
public List getAddresses() {
return fAddressGroup.getAddresses();
}
}

Map Person to the PERSON table and Address to the ADDRESS table; nothing weird 
required in repository.xml.

-steve

Steve Clark
Technology Applications Team
Natural Resources Research Center/USGS
[EMAIL PROTECTED]
(970)226-9291

List-Id: OJB Users List ojb-user.db.apache.org
Subject: o/r mapping question
Date: Thu, 30 Oct 2003 21:14:16 -0500
Thread-Topic: o/r mapping question
From: Robert J Celestino [EMAIL PROTECTED]
To: OJB Users List [EMAIL PROTECTED]

Hello all,

I am stumped by what is posibly a very simple mapping problem. 

Consider something like this
   Person is stored in the person table
   Person has-a AddressGroup. AddressGroup is not stored in the DB
   AddressGroup has a list of Addresses
   Address is stored in the address table. Has a column 
   called PersonId that indicates the person it belongs to

This is a little contrived but bear with me. 

Clearly Person could have a list of addresses, but for various reasons it has 
the intermediate class AddressGroup instead. 

I know how to solve this if AddressGroup was stored in the DB, but it is not. 
It is purely a domain class. 

How can I get ojb to create and write this class without actually writing it to 
the db? 
   
Thanks very much
Bob c


Bob Celestino
SAS Research and Development
919 - 531 - 9425
[EMAIL PROTECTED]

SAS - The Power to Know

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



Re: RE: Another silly newbie mapping question

2003-11-02 Thread jeichels
Still no clue on what is wrong with this.




- Original Message -
From: [EMAIL PROTECTED]
Date: Friday, October 31, 2003 3:19 pm
Subject: Re: RE: Another silly newbie mapping question

 Thank you Robert, but Offers are permanent pieces of information 
 in the database whereas OrderItems come and go.
 
 
 The site holds numerous Offers which are stored permanently in the 
 database.   The customer has a shopping cart which is basically an 
 OrderItem based on those Offers.   So when I get an OrderItem from 
 the database I just wanted to also be able to pull the associated 
 Offer though I would never want Offer to change.
 
 I have looked in the ojb's repository_junit.xml test cases which 
 have always helped me in the past, but i think I am just missing 
 something.   The Collection of OrderItems pull, but not these 
 attached Offer objects.   I have verified the database, etc.   The 
 messages don't seem to show it even attempting to pull the Offer.
 
 I have a similar reference for Member and Location that is working 
 so it is confusing to me.  Thank you for any ideas as I am about 
 plum out of them.
 
 JohnE
 
 
 
 
 
 
 
 - Original Message -
 From: Robert J Celestino [EMAIL PROTECTED]
 Date: Friday, October 31, 2003 10:11 am
 Subject: RE: Another silly newbie mapping question
 
  Hello John, 
  
  I think you want auto-update=true instead of false here: 
  
 reference-descriptor
 name=offer
 class-
 ref=com.jobbank.jobbank.model.offer.OfferVO
 auto-retrieve=true
 auto-update=false
 auto-delete=false
   foreignkey field-ref=offerId/
 /reference-descriptor
  
  my thinking is that when you store the OrderItem the Offer is 
 not 
  writen bacause auto-update is false. Then when reading the 
  OrderItem back out, the Offer is not there. 
  
  Bob c
  
  
  
  Bob Celestino
  SAS Research and Development
  919 - 531 - 9425
  [EMAIL PROTECTED]
  
  SAS - The Power to Know
  
  
-Original Message-
From: [EMAIL PROTECTED] [EMAIL PROTECTED] 
Sent: Friday, October 31, 2003 5:01 AM
To: OJB Users List
Subject: Re: Another silly newbie mapping question


I give up for the night.   BTW I am using Release Candidate 2.

Not sure it matters, but I am using 
PersistentFieldClass=org.apache.ojb.broker.metadata.fieldacc
ess.PersistentNestedFieldMaxPerformanceImpl so that I could 
use '-' Single Table Aggregation as it wasn't implemented 
in the default implementation.

From the archives it seemed ok to map multiple primary keys 
to one primary key.


- Original Message -
From: [EMAIL PROTECTED]
Date: Friday, October 31, 2003 2:49 am
Subject: Re: Another silly newbie mapping question

 Still no luck.  I noticed that my primary key order might have
 something to do with it so I switched the order within the 
 OrderItemVO mapping, but it didn't seem to help.   I 
realized that 
 based on the logging that OJB does not seem to even be 
  trying to 
 materialize the OfferVO object as no notice is printed 
 about 
  it 
 trying.   Here is my logging:
 
 
 [org.apache.ojb.broker.accesslayer.JdbcAccessImpl] DEBUG:
 executeQuery : Query from class 
 com.jobbank.jobbank.model.order.OrderItemVO where 
 
[EMAIL PROTECTED]
oker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: 
SQL:SELECT A0.modified,A0.offerid,A0.disabled,A0.mid,A0.offerq
 uantity,A0.orderid,A0.buylater,A0.added FROM orderitem A0 
  WHERE 
 (mid =  ? ) AND orderid =  ?
 [org.apache.ojb.broker.accesslayer.JdbcAccessImpl] DEBUG: 
 executeQuery: [EMAIL PROTECTED]: 
  SELECT 
 
A0.modified,A0.offerid,A0.disabled,A0.mid,A0.offerquantity,A
0.orderid,A0.buylater,A0.added FROM orderitem A0 WHERE (mid 
=  2 ) AND orderid =  0
 [org.apache.ojb.broker.accesslayer.RsIterator] DEBUG: 
hasNext() - 
 true[org.apache.ojb.broker.accesslayer.RsIterator] DEBUG: 
 hasNext() - false
 [org.apache.ojb.broker.core.PersistenceBrokerImpl] DEBUG: 
PB.close 
 was called: 
  [EMAIL PROTECTED]8
 TEST CartItem: [2|0|1|1|false|[2003-10-31 02:50:11.515|2003-
  10-31 
 02:50:11.515|false]|]WITH OFFER: null
 TEST:  After ShoppingCartActions.populateMemberShoppingCart()
 
 
 
 
 
 
 - Original Message -
 From: [EMAIL PROTECTED]
 Date: Friday, October 31, 2003 1:56 am
 Subject: Another silly newbie mapping question
 
  
  I have worked out much harder mapping problems then this, but
 for
  some reason I am still a bit new on this stuff and making no
  headway.  I would appreciate a more seasoned glance.
  
  Problem:  OfferVO is not being materialized after succesfully
  retrieving

Re: RE: Another silly newbie mapping question

2003-11-02 Thread jeichels
So, I iterated through the Collection of orderItems I had retrieved and extracted the 
offers attached by each manually and it worked.

I guess I am to the point where I don't know why the getCollectionByQuery() won't pull 
automagically each Offer.  Manual means work, but are very inefficient and I want to 
understand this just for the sake of understanding.

JohnE



- Original Message -
From: [EMAIL PROTECTED]
Date: Sunday, November 2, 2003 5:24 pm
Subject: Re: RE: Another silly newbie mapping question

 Still no clue on what is wrong with this.
 
 
 
 
 - Original Message -
 From: [EMAIL PROTECTED]
 Date: Friday, October 31, 2003 3:19 pm
 Subject: Re: RE: Another silly newbie mapping question
 
  Thank you Robert, but Offers are permanent pieces of information 
  in the database whereas OrderItems come and go.
  
  
  The site holds numerous Offers which are stored permanently in 
 the 
  database.   The customer has a shopping cart which is basically 
 an 
  OrderItem based on those Offers.   So when I get an OrderItem 
 from 
  the database I just wanted to also be able to pull the 
 associated 
  Offer though I would never want Offer to change.
  
  I have looked in the ojb's repository_junit.xml test cases which 
  have always helped me in the past, but i think I am just missing 
  something.   The Collection of OrderItems pull, but not these 
  attached Offer objects.   I have verified the database, etc.   
 The 
  messages don't seem to show it even attempting to pull the Offer.
  
  I have a similar reference for Member and Location that is 
 working 
  so it is confusing to me.  Thank you for any ideas as I am about 
  plum out of them.
  
  JohnE
  
  
  
  
  
  
  
  - Original Message -
  From: Robert J Celestino [EMAIL PROTECTED]
  Date: Friday, October 31, 2003 10:11 am
  Subject: RE: Another silly newbie mapping question
  
   Hello John, 
   
   I think you want auto-update=true instead of false here: 
   
  reference-descriptor
  name=offer
  class-
  ref=com.jobbank.jobbank.model.offer.OfferVO
  auto-retrieve=true
  auto-update=false
  auto-delete=false
foreignkey field-ref=offerId/
  /reference-descriptor
   
   my thinking is that when you store the OrderItem the Offer is 
  not 
   writen bacause auto-update is false. Then when reading the 
   OrderItem back out, the Offer is not there. 
   
   Bob c
   
   
   ---
 -
   Bob Celestino
   SAS Research and Development
   919 - 531 - 9425
   [EMAIL PROTECTED]
   
   SAS - The Power to Know
   
   
 -Original Message-
 From: [EMAIL PROTECTED] [EMAIL PROTECTED] 
 Sent: Friday, October 31, 2003 5:01 AM
 To: OJB Users List
 Subject: Re: Another silly newbie mapping question
 
 
 I give up for the night.   BTW I am using Release Candidate 2.
 
 Not sure it matters, but I am using 
 PersistentFieldClass=org.apache.ojb.broker.metadata.fieldacc
 ess.PersistentNestedFieldMaxPerformanceImpl so that I could 
 use '-' Single Table Aggregation as it wasn't implemented 
 in the default implementation.
 
 From the archives it seemed ok to map multiple primary keys 
 to one primary key.
 
 
 - Original Message -
 From: [EMAIL PROTECTED]
 Date: Friday, October 31, 2003 2:49 am
 Subject: Re: Another silly newbie mapping question
 
  Still no luck.  I noticed that my primary key order might 
 have something to do with it so I switched the order 
 within the 
  OrderItemVO mapping, but it didn't seem to help.   I 
 realized that 
  based on the logging that OJB does not seem to even be 
   trying to 
  materialize the OfferVO object as no notice is printed 
  about 
   it 
  trying.   Here is my logging:
  
  
  [org.apache.ojb.broker.accesslayer.JdbcAccessImpl] DEBUG:
  executeQuery : Query from class 
  com.jobbank.jobbank.model.order.OrderItemVO where 
  
 [EMAIL PROTECTED]
 oker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: 
 SQL:SELECT A0.modified,A0.offerid,A0.disabled,A0.mid,A0.offerq
  uantity,A0.orderid,A0.buylater,A0.added FROM orderitem A0 
   WHERE 
  (mid =  ? ) AND orderid =  ?
  [org.apache.ojb.broker.accesslayer.JdbcAccessImpl] DEBUG: 
  executeQuery: [EMAIL PROTECTED]: 
   SELECT 
  
 A0.modified,A0.offerid,A0.disabled,A0.mid,A0.offerquantity,A
 0.orderid,A0.buylater,A0.added FROM orderitem A0 WHERE (mid 
 =  2 ) AND orderid =  0
  [org.apache.ojb.broker.accesslayer.RsIterator] DEBUG: 
 hasNext() - 
  true[org.apache.ojb.broker.accesslayer.RsIterator] DEBUG: 
  hasNext() - false
  [org.apache.ojb.broker.core.PersistenceBrokerImpl] DEBUG: 
 PB.close 
  was called: 
   [EMAIL PROTECTED]8
  TEST CartItem

Another silly newbie mapping question

2003-10-31 Thread jeichels

I have worked out much harder mapping problems then this, but for some reason I am 
still a bit new on this stuff and making no headway.  I would appreciate a more 
seasoned glance.

Problem:  OfferVO is not being materialized after succesfully retrieving the 
Collection of OrderItemVO by using getCollectionByQuery(query).  Each OrderItemVO 
should have exactly one OfferVO, but the reference to the OfferVO only returns null.



!-- Definitions for the OrderItemVO object --
class-descriptor class=com.jobbank.jobbank.model.order.OrderItemVO 
table=orderitem
field-descriptor
name=memberId
column=mid
jdbc-type=INTEGER
primarykey=true
/
field-descriptor
name=orderId
column=orderid
jdbc-type=INTEGER
primarykey=true
/
field-descriptor
name=offerId
column=offerid
jdbc-type=INTEGER
primarykey=true
/
reference-descriptor
name=offer
class-ref=com.jobbank.jobbank.model.offer.OfferVO
auto-retrieve=true
auto-update=false
auto-delete=false
  foreignkey field-ref=offerId/
/reference-descriptor
/class-descriptor




!-- Definitions for the OfferVO object --
class-descriptor class=com.jobbank.jobbank.model.offer.OfferVO table=offer
  auto-retrieve=true auto-update=false auto-delete=false
field-descriptor
name=offerId
column=offerid
jdbc-type=INTEGER
primarykey=true
/
field-descriptor
name=name
column=name
jdbc-type=VARCHAR
/
field-descriptor
name=offerPrice
column=offerprice
jdbc-type=DOUBLE
/
collection-descriptor
name=offeredProducts
element-class-ref=com.jobbank.jobbank.model.offer.OfferedProductVO
proxy=true
inverse-foreignkey field-ref=offerId/
/collection-descriptor
/class-descriptor


Thank you muchly,

JohnE



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



Re: Another silly newbie mapping question

2003-10-31 Thread jeichels
I give up for the night.   BTW I am using Release Candidate 2.

Not sure it matters, but I am using 
PersistentFieldClass=org.apache.ojb.broker.metadata.fieldaccess.PersistentNestedFieldMaxPerformanceImpl
 so that I could use '-' Single Table Aggregation as it wasn't implemented in the 
default implementation.

From the archives it seemed ok to map multiple primary keys to one primary key.


- Original Message -
From: [EMAIL PROTECTED]
Date: Friday, October 31, 2003 2:49 am
Subject: Re: Another silly newbie mapping question

 Still no luck.  I noticed that my primary key order might have 
 something to do with it so I switched the order within the 
 OrderItemVO mapping, but it didn't seem to help.   I realized that 
 based on the logging that OJB does not seem to even be trying to 
 materialize the OfferVO object as no notice is printed about it 
 trying.   Here is my logging:
 
 
 [org.apache.ojb.broker.accesslayer.JdbcAccessImpl] DEBUG: 
 executeQuery : Query from class 
 com.jobbank.jobbank.model.order.OrderItemVO where 
 [EMAIL PROTECTED] DEBUG: SQL:SELECT 
 A0.modified,A0.offerid,A0.disabled,A0.mid,A0.offerq
 uantity,A0.orderid,A0.buylater,A0.added FROM orderitem A0 WHERE 
 (mid =  ? ) AND orderid =  ?
 [org.apache.ojb.broker.accesslayer.JdbcAccessImpl] DEBUG: 
 executeQuery: [EMAIL PROTECTED]: SELECT 
 A0.modified,A0.offerid,A0.disabled,A0.mid,A0.offerquantity,A0.orderid,A0.buylater,A0.added
  FROM orderitem A0 WHERE (mid =  2 ) AND orderid =  0
 [org.apache.ojb.broker.accesslayer.RsIterator] DEBUG: hasNext() - 
 true[org.apache.ojb.broker.accesslayer.RsIterator] DEBUG: 
 hasNext() - false
 [org.apache.ojb.broker.core.PersistenceBrokerImpl] DEBUG: PB.close 
 was called: [EMAIL PROTECTED]
 8
 TEST CartItem: [2|0|1|1|false|[2003-10-31 02:50:11.515|2003-10-31 
 02:50:11.515|false]|]WITH OFFER: null
 TEST:  After ShoppingCartActions.populateMemberShoppingCart()
 
 
 
 
 
 
 - Original Message -
 From: [EMAIL PROTECTED]
 Date: Friday, October 31, 2003 1:56 am
 Subject: Another silly newbie mapping question
 
  
  I have worked out much harder mapping problems then this, but 
 for 
  some reason I am still a bit new on this stuff and making no 
  headway.  I would appreciate a more seasoned glance.
  
  Problem:  OfferVO is not being materialized after succesfully 
  retrieving the Collection of OrderItemVO by using 
  getCollectionByQuery(query).  Each OrderItemVO should have 
 exactly 
  one OfferVO, but the reference to the OfferVO only returns null.
  
  
  
  !-- Definitions for the OrderItemVO object --
  class-descriptor 
  class=com.jobbank.jobbank.model.order.OrderItemVO 
 table=orderitemfield-descriptor
 name=memberId
 column=mid
 jdbc-type=INTEGER
 primarykey=true
 /
 field-descriptor
 name=orderId
 column=orderid
 jdbc-type=INTEGER
 primarykey=true
 /
 field-descriptor
 name=offerId
 column=offerid
 jdbc-type=INTEGER
 primarykey=true
 /
 reference-descriptor
 name=offer
 class-ref=com.jobbank.jobbank.model.offer.OfferVO
 auto-retrieve=true
 auto-update=false
 auto-delete=false
   foreignkey field-ref=offerId/
 /reference-descriptor
  /class-descriptor
  
  
  
  
  !-- Definitions for the OfferVO object --
  class-descriptor 
 class=com.jobbank.jobbank.model.offer.OfferVO 
  table=offer  auto-retrieve=true auto-
  update=false auto-delete=false
 field-descriptor
 name=offerId
 column=offerid
 jdbc-type=INTEGER
 primarykey=true
 /
 field-descriptor
 name=name
 column=name
 jdbc-type=VARCHAR
 /
 field-descriptor
 name=offerPrice
 column=offerprice
 jdbc-type=DOUBLE
 /
 collection-descriptor
 name=offeredProducts
 element-class-
  ref=com.jobbank.jobbank.model.offer.OfferedProductVO   
 
  proxy=trueinverse-foreignkey field-ref=offerId/
 /collection-descriptor
  /class-descriptor
  
  
  Thank you muchly,
  
  JohnE
  
  
  
  -
 --
  --
  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]
 
 


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



RE: Another silly newbie mapping question

2003-10-31 Thread Robert J Celestino
Hello John, 

I think you want auto-update=true instead of false here: 

reference-descriptor
name=offer
class-ref=com.jobbank.jobbank.model.offer.OfferVO
auto-retrieve=true
auto-update=false
auto-delete=false
  foreignkey field-ref=offerId/
/reference-descriptor

my thinking is that when you store the OrderItem the Offer is not writen bacause 
auto-update is false. Then when reading the OrderItem back out, the Offer is not 
there. 

Bob c



Bob Celestino
SAS Research and Development
919 - 531 - 9425
[EMAIL PROTECTED]

SAS - The Power to Know


   -Original Message-
   From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
   Sent: Friday, October 31, 2003 5:01 AM
   To: OJB Users List
   Subject: Re: Another silly newbie mapping question
   
   
   I give up for the night.   BTW I am using Release Candidate 2.
   
   Not sure it matters, but I am using 
   PersistentFieldClass=org.apache.ojb.broker.metadata.fieldacc
   ess.PersistentNestedFieldMaxPerformanceImpl so that I could 
   use '-' Single Table Aggregation as it wasn't implemented 
   in the default implementation.
   
   From the archives it seemed ok to map multiple primary keys 
   to one primary key.
   
   
   - Original Message -
   From: [EMAIL PROTECTED]
   Date: Friday, October 31, 2003 2:49 am
   Subject: Re: Another silly newbie mapping question
   
Still no luck.  I noticed that my primary key order might have
something to do with it so I switched the order within the 
OrderItemVO mapping, but it didn't seem to help.   I 
   realized that 
based on the logging that OJB does not seem to even be trying to 
materialize the OfferVO object as no notice is printed about it 
trying.   Here is my logging:


[org.apache.ojb.broker.accesslayer.JdbcAccessImpl] DEBUG:
executeQuery : Query from class 
com.jobbank.jobbank.model.order.OrderItemVO where 

   [EMAIL PROTECTED]
   oker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: 
   SQL:SELECT A0.modified,A0.offerid,A0.disabled,A0.mid,A0.offerq
uantity,A0.orderid,A0.buylater,A0.added FROM orderitem A0 WHERE 
(mid =  ? ) AND orderid =  ?
[org.apache.ojb.broker.accesslayer.JdbcAccessImpl] DEBUG: 
executeQuery: [EMAIL PROTECTED]: SELECT 

   A0.modified,A0.offerid,A0.disabled,A0.mid,A0.offerquantity,A
   0.orderid,A0.buylater,A0.added FROM orderitem A0 WHERE (mid 
   =  2 ) AND orderid =  0
[org.apache.ojb.broker.accesslayer.RsIterator] DEBUG: 
   hasNext() - 
true[org.apache.ojb.broker.accesslayer.RsIterator] DEBUG: 
hasNext() - false
[org.apache.ojb.broker.core.PersistenceBrokerImpl] DEBUG: 
   PB.close 
was called: [EMAIL PROTECTED]
8
TEST CartItem: [2|0|1|1|false|[2003-10-31 02:50:11.515|2003-10-31 
02:50:11.515|false]|]WITH OFFER: null
TEST:  After ShoppingCartActions.populateMemberShoppingCart()






- Original Message -
From: [EMAIL PROTECTED]
Date: Friday, October 31, 2003 1:56 am
Subject: Another silly newbie mapping question

 
 I have worked out much harder mapping problems then this, but
for
 some reason I am still a bit new on this stuff and making no
 headway.  I would appreciate a more seasoned glance.
 
 Problem:  OfferVO is not being materialized after succesfully
 retrieving the Collection of OrderItemVO by using 
 getCollectionByQuery(query).  Each OrderItemVO should have 
exactly
 one OfferVO, but the reference to the OfferVO only returns null.
 
 
 
 !-- Definitions for the OrderItemVO object -- 
   class-descriptor
 class=com.jobbank.jobbank.model.order.OrderItemVO 
table=orderitemfield-descriptor
name=memberId
column=mid
jdbc-type=INTEGER
primarykey=true
/
field-descriptor
name=orderId
column=orderid
jdbc-type=INTEGER
primarykey=true
/
field-descriptor
name=offerId
column=offerid
jdbc-type=INTEGER
primarykey=true
/
reference-descriptor
name=offer
class-ref=com.jobbank.jobbank.model.offer.OfferVO
auto-retrieve=true
auto-update=false
auto-delete=false
  foreignkey field-ref=offerId/
/reference-descriptor
 /class-descriptor
 
 
 
 
 !-- Definitions for the OfferVO object -- class-descriptor
class=com.jobbank.jobbank.model.offer.OfferVO
 table=offer  auto-retrieve=true auto-
 update=false auto-delete=false
field-descriptor
name=offerId
column=offerid
jdbc-type=INTEGER
primarykey=true

Re: RE: Another silly newbie mapping question

2003-10-31 Thread jeichels
Thank you Robert, but Offers are permanent pieces of information in the database 
whereas OrderItems come and go.


The site holds numerous Offers which are stored permanently in the database.   The 
customer has a shopping cart which is basically an OrderItem based on those Offers.   
So when I get an OrderItem from the database I just wanted to also be able to pull the 
associated Offer though I would never want Offer to change.

I have looked in the ojb's repository_junit.xml test cases which have always helped me 
in the past, but i think I am just missing something.   The Collection of OrderItems 
pull, but not these attached Offer objects.   I have verified the database, etc.   The 
messages don't seem to show it even attempting to pull the Offer.

I have a similar reference for Member and Location that is working so it is confusing 
to me.  Thank you for any ideas as I am about plum out of them.

JohnE







- Original Message -
From: Robert J Celestino [EMAIL PROTECTED]
Date: Friday, October 31, 2003 10:11 am
Subject: RE: Another silly newbie mapping question

 Hello John, 
 
 I think you want auto-update=true instead of false here: 
 
reference-descriptor
name=offer
class-ref=com.jobbank.jobbank.model.offer.OfferVO
auto-retrieve=true
auto-update=false
auto-delete=false
  foreignkey field-ref=offerId/
/reference-descriptor
 
 my thinking is that when you store the OrderItem the Offer is not 
 writen bacause auto-update is false. Then when reading the 
 OrderItem back out, the Offer is not there. 
 
 Bob c
 
 
 
 Bob Celestino
 SAS Research and Development
 919 - 531 - 9425
 [EMAIL PROTECTED]
 
 SAS - The Power to Know
 
 
   -Original Message-
   From: [EMAIL PROTECTED] [EMAIL PROTECTED] 
   Sent: Friday, October 31, 2003 5:01 AM
   To: OJB Users List
   Subject: Re: Another silly newbie mapping question
   
   
   I give up for the night.   BTW I am using Release Candidate 2.
   
   Not sure it matters, but I am using 
   PersistentFieldClass=org.apache.ojb.broker.metadata.fieldacc
   ess.PersistentNestedFieldMaxPerformanceImpl so that I could 
   use '-' Single Table Aggregation as it wasn't implemented 
   in the default implementation.
   
   From the archives it seemed ok to map multiple primary keys 
   to one primary key.
   
   
   - Original Message -
   From: [EMAIL PROTECTED]
   Date: Friday, October 31, 2003 2:49 am
   Subject: Re: Another silly newbie mapping question
   
Still no luck.  I noticed that my primary key order might have
something to do with it so I switched the order within the 
OrderItemVO mapping, but it didn't seem to help.   I 
   realized that 
based on the logging that OJB does not seem to even be 
 trying to 
materialize the OfferVO object as no notice is printed about 
 it 
trying.   Here is my logging:


[org.apache.ojb.broker.accesslayer.JdbcAccessImpl] DEBUG:
executeQuery : Query from class 
com.jobbank.jobbank.model.order.OrderItemVO where 

   [EMAIL PROTECTED]
   oker.accesslayer.sql.SqlGeneratorDefaultImpl] DEBUG: 
   SQL:SELECT A0.modified,A0.offerid,A0.disabled,A0.mid,A0.offerq
uantity,A0.orderid,A0.buylater,A0.added FROM orderitem A0 
 WHERE 
(mid =  ? ) AND orderid =  ?
[org.apache.ojb.broker.accesslayer.JdbcAccessImpl] DEBUG: 
executeQuery: [EMAIL PROTECTED]: 
 SELECT 

   A0.modified,A0.offerid,A0.disabled,A0.mid,A0.offerquantity,A
   0.orderid,A0.buylater,A0.added FROM orderitem A0 WHERE (mid 
   =  2 ) AND orderid =  0
[org.apache.ojb.broker.accesslayer.RsIterator] DEBUG: 
   hasNext() - 
true[org.apache.ojb.broker.accesslayer.RsIterator] DEBUG: 
hasNext() - false
[org.apache.ojb.broker.core.PersistenceBrokerImpl] DEBUG: 
   PB.close 
was called: 
 [EMAIL PROTECTED]8
TEST CartItem: [2|0|1|1|false|[2003-10-31 02:50:11.515|2003-
 10-31 
02:50:11.515|false]|]WITH OFFER: null
TEST:  After ShoppingCartActions.populateMemberShoppingCart()






- Original Message -
From: [EMAIL PROTECTED]
Date: Friday, October 31, 2003 1:56 am
Subject: Another silly newbie mapping question

 
 I have worked out much harder mapping problems then this, but
for
 some reason I am still a bit new on this stuff and making no
 headway.  I would appreciate a more seasoned glance.
 
 Problem:  OfferVO is not being materialized after succesfully
 retrieving the Collection of OrderItemVO by using 
 getCollectionByQuery(query).  Each OrderItemVO should have 
exactly
 one OfferVO, but the reference to the OfferVO only returns 
 null. 
 
 
 !-- Definitions for the OrderItemVO object -- 
   class-descriptor
 class=com.jobbank.jobbank.model.order.OrderItemVO 
table

o/r mapping question

2003-10-30 Thread Robert J Celestino
Hello all,

I am stumped by what is posibly a very simple mapping problem. 

Consider something like this
Person is stored in the person table
Person has-a AddressGroup. AddressGroup is not stored in the DB
AddressGroup has a list of Addresses
Address is stored in the address table. Has a column 
called PersonId that indicates the person it belongs to

This is a little contrived but bear with me. 

Clearly Person could have a list of addresses, but for various reasons it has the 
intermediate class AddressGroup instead. 

I know how to solve this if AddressGroup was stored in the DB, but it is not. It is 
purely a domain class. 

How can I get ojb to create and write this class without actually writing it to the 
db? 

Thanks very much
Bob c


Bob Celestino
SAS Research and Development
919 - 531 - 9425
[EMAIL PROTECTED]

SAS - The Power to Know

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



RE: o/r mapping question

2003-10-30 Thread Lance Eason
Sound like AddressGroup is a collection of addresses.  Through the 'collection-class' 
attribute on collection descriptors you can specify your own implementation of the 
collection class to use for a particular relationship.  I think it needs to implement 
Collection, but other than that it seems pretty straightforward.

class-descriptor class=com.foo.Person
   ...
   collection-descriptor
  name=addresses
  element-class-ref=com.foo.Address
  collection-class=com.foo.AddressGroup
   
  inverse-foreignkey .../
   /collection-descriptor
/class-descriptor


-Original Message-
From: Robert J Celestino [mailto:[EMAIL PROTECTED]
Sent: Thursday, October 30, 2003 8:14 PM
To: OJB Users List
Subject: o/r mapping question


Hello all,

I am stumped by what is posibly a very simple mapping problem. 

Consider something like this
Person is stored in the person table
Person has-a AddressGroup. AddressGroup is not stored in the DB
AddressGroup has a list of Addresses
Address is stored in the address table. Has a column 
called PersonId that indicates the person it belongs to

This is a little contrived but bear with me. 

Clearly Person could have a list of addresses, but for various reasons it has the 
intermediate class AddressGroup instead. 

I know how to solve this if AddressGroup was stored in the DB, but it is not. It is 
purely a domain class. 

How can I get ojb to create and write this class without actually writing it to the 
db? 

Thanks very much
Bob c


Bob Celestino
SAS Research and Development
919 - 531 - 9425
[EMAIL PROTECTED]

SAS - The Power to Know

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



Re: o/r mapping question

2003-10-30 Thread Brian McCallister
Solution 1:
Implement AddressGroup as a custom collection (implementing Manageable  
Collection) used to hold the address instances. This muddies the domain  
model a bit as AddressGroup then needs to know about  
ManageableCollection.

Solution 2:
Map two classes to the same table (I used an existing application hence  
the names of tables):

kim=# \d users
\d   Table public.users
   Column   |  Type  | Modifiers
++---
 id | integer| not null
 handle | character varying(32)  |
 password   | character varying(255) |
 first_name | character varying(255) |
 last_name  | character varying(255) |
 aim_name   | character varying(255) |
 email  | character varying(255) |
Indexes: users_pkey primary key btree (id)
kim=# \d gifts
 Table public.gifts
 Column  |  Type   | Modifiers
-+-+---
 id  | integer | not null
 name| character varying(255)  |
 description | character varying(2000) |
 level_of_desire | integer | default 0
 where_to_buy| character varying(2000) |
 cost| character varying(255)  |
 for_user_id | integer | not null
 from_user_id| integer |
 suggest_user_id | integer |
Indexes: gifts_pkey primary key btree (id)
Foreign Key constraints: gifts_fk_1 FOREIGN KEY (suggest_user_id)  
REFERENCES users(id) ON UPDATE NO ACTION ON DELETE NO ACTION,
 gifts_fk_2 FOREIGN KEY (for_user_id)  
REFERENCES users(id) ON UPDATE NO ACTION ON DELETE NO ACTION,
 gifts_fk_3 FOREIGN KEY (from_user_id)  
REFERENCES users(id) ON UPDATE NO ACTION ON DELETE NO ACTION

kim=#

class-descriptor class=org.skife.kim.model.Foo table=USERS
field-descriptor name=id column=ID jdbc-type=INTEGER  
primarykey=true autoincrement=true/
reference-descriptor name=bar  
class-ref=org.skife.kim.model.Bar
foreignkey field-ref=id/
/reference-descriptor
/class-descriptor

class-descriptor class=org.skife.kim.model.Bar table=USERS
field-descriptor name=id column=ID jdbc-type=INTEGER  
primarykey=true autoincrement=true/
collection-descriptor name=gifts  
element-class-ref=org.skife.kim.model.Gift
 
collection- 
class=org.apache.ojb.broker.util.collections.ManageableHashSet
inverse-foreignkey field-ref=for_user_id/
/collection-descriptor
/class-descriptor

class-descriptor class=org.skife.kim.model.Bang table=GIFTS
field-descriptor name=id column=ID jdbc-type=INTEGER  
primarykey=true autoincrement=true/
field-descriptor name=for_user_id column=FOR_USER_ID  
jdbc-type=INTEGER access=anonymous/
reference-descriptor name=bar  
class-ref=org.skife.kim.model.User
foreignkey field-ref=for_user_id/
/reference-descriptor
/class-descriptor

public class Foo
{
public Integer id;
public Bar bar;
}
public class Bar
{
public Integer id;
public Set gifts;
}
public class Bang
{
public Integer id;
public Bar bar;
}
public void testFooBar() throws Exception
{
foo = new Foo();
bar = new Bar();
bang = new Bang();
PersistenceBroker broker =  
PersistenceBrokerFactory.defaultPersistenceBroker();
foo.bar = bar;
bar.gifts = new HashSet();
bar.gifts.add(bang);
bang.bar = bar;
broker.store(foo);
broker.store(bar);
broker.store(bang);
broker.clearCache();

Criteria crit = new Criteria();
crit.addEqualTo(id, this.foo.id);
Query query = new QueryByCriteria(Foo.class, crit);
Foo thing = (Foo) broker.getObjectByQuery(query);
Assert.assertEquals(thing.id, foo.id);
Assert.assertEquals(1, foo.bar.gifts.size());
}
.
Time: 2.108
OK (1 test)

Neither one is ideal, but the ideal is having the data model and object  
model match up perfectly. The second leaves your object model  
independent of your persistence mechanism at least but sort of feels  
dirty to me.

-Brian

On Thursday, October 30, 2003, at 09:14 PM, Robert J Celestino wrote:

Hello all,

I am stumped by what is posibly a very simple mapping problem.

Consider something like this
Person is stored in the person table
Person has-a AddressGroup. AddressGroup is not stored in the DB
AddressGroup has a list of Addresses
Address is stored in the address table. Has a column
called PersonId that indicates the person it belongs to
This is a little contrived but bear with me.

Clearly Person could have a list of addresses, but for various reasons  
it has the intermediate class AddressGroup instead.

I know how to solve this if AddressGroup was stored in the DB, but it  
is not. It is purely a domain class.

How can I get ojb to create and write this class without actually  

Re: N same class mapping question...

2003-10-29 Thread Oleg Nitz
Hi Brian,

I have fixed the OTM bug (M:N relations wasn't updated). 
Thanks for detailed bug report.

Regards,
 Oleg

On Tuesday 14 October 2003 14:16, Brian McCallister wrote:
 On Tuesday, October 14, 2003, at 09:33 AM, [EMAIL PROTECTED] wrote:
  Hej Brian,
 
  -Original Message-
  From: Brian McCallister [mailto:[EMAIL PROTECTED]
 
  I have mixed and matched the value, but it hasn't mattered. I had
  thought it might care so I tried various combinations. It in
  this vase
  being a nebulous entity who thwarts my plans, as to my knowledge
  neither OJB nor Postgres care about case of table names.
 
  Which API do you use?

 OTM (with OQL and Iterators instead of DLists -- see findById(...)
 below ). The project is part of my OTM learning process so I can write
 some docs on it.

   Which concrete class is instantiated
  for the list field?

 Default - I don't specify anything so should be a Vector.

  Can you post the code that you use
  to persist the objects?

 Of course, I will put a tarball (
 http://kasparov.skife.org/kim-broken.tar.gz (includes jars so is big, 8
 megs)) of the whole project up, the relevent pieces:

 Test Failure:
 ---
 There was 1 failure:
 1)
 testRequestFriend(org.skife.kim.model.TestUserRelations)junit.framework.
 AssertionFailedError: expected:1 but was:0
   at
 org.skife.kim.model.TestUserRelations.testRequestFriend(TestUserRelation
 s.java:76)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at
 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav
 a:39)
   at
 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor
 Impl.java:25)
   at
 com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java:
 12)
 ---
 FAILURES!!!
 Tests run: 1,  Failures: 1,  Errors: 0

 The Test: (one and two are created in the setup and removed in the
 teardown)
 -
  public void testRequestFriend() throws Exception
  {
  Unit unit = Unit.begin();
  one = UserRepository.findById(one.getId(), unit);
  two = UserRepository.findById(two.getId(), unit);
  one.addFriend(two);
  unit.commit();

  TestTools.clearCache();

  unit = Unit.begin();
  one = UserRepository.findById(one.getId(), unit);
  List friends = one.getFriends();
  Assert.assertEquals(1, one.getFriends().size()); // This
 Assertion Fails
  unit.commit();
  }
 ---

 Unit simply provides a convenience wrapper around OTMConnections and
 Transactions:
 --
 package org.skife.kim.infra;

 import org.apache.ojb.otm.core.Transaction;
 import org.apache.ojb.otm.OTMConnection;
 import org.apache.ojb.otm.kit.SimpleKit;
 import org.apache.ojb.broker.PersistenceBrokerFactory;

 /**
   * Unit of Work shortened for typing purposes
   *
   * TODO: Add a factory method that takes a long argument and will
 rollback the transaction
   *   after an elapsed time has passed. Each getConnection() call
 extends the time
   *   by the initial value. This allows for clearing the connection
 before the session
   *   times out in web apps
   */
 public class Unit
 {
  private Transaction transaction;
  private OTMConnection connection;

  private Unit()
  {
  this.connection =
 SimpleKit.getInstance().acquireConnection(PersistenceBrokerFactory.getDe
 faultKey());
  this.transaction =
 SimpleKit.getInstance().getTransaction(this.connection);
  }

  public static Unit begin()
  {
  Unit unit = new Unit();
  unit.transaction.begin();
  return unit;
  }

  /**
   * @throws org.skife.kim.infra.UnitException if the Unit of Work
 has already been committed
   *   or rolled back - either via this or the
 underlying
   *   Transaction/OTMConnection
   */
  public void commit() throws UnitException
  {
  if (! transaction.isInProgress())
  {
  throw new UnitException(Unit of work already closed);
  }
  this.transaction.commit();
  this.connection.close();
  }

  /**
   * @throws org.skife.kim.infra.UnitException if the Unit of Work
 has already been committed
   *   or rolled back - either via this or the
 underlying
   *   Transaction/OTMConnection
   */
  public void rollback() throws UnitException
  {
  if (! transaction.isInProgress())
  {
  throw new UnitException(Unit of work already closed);
  }
  this.transaction.rollback();
  this.connection.close();
  }

  /**
   * @return the OTMConnection in use by this Unit. It is already
 transactional
   */
  OTMConnection getConnection()
  {
   

Re: N same class mapping question...

2003-10-14 Thread Brian McCallister
I have mixed and matched the value, but it hasn't mattered. I had 
thought it might care so I tried various combinations. It in this vase 
being a nebulous entity who thwarts my plans, as to my knowledge 
neither OJB nor Postgres care about case of table names.

Will experiment on that one further =)

-Brian

On Tuesday, October 14, 2003, at 08:42 AM, [EMAIL PROTECTED] wrote:

Hello Brian,

-Original Message-
class-descriptor class=test.User table=USERS
[..]

-- Schema Def'n --

 table name=user_friend description=M:N mapping table
for user's friends
[..]

 foreign-key foreignTable=users
Why is 'users' lower-case here and uppercase above?
Might cause problems depending on the RDMBS.

 reference local=friend_id foreign=id/
 /foreign-key
 /table
Olli

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


RE: N same class mapping question...

2003-10-14 Thread oliver . matz
Hej Brian,

 -Original Message-
 From: Brian McCallister [mailto:[EMAIL PROTECTED]
 
 I have mixed and matched the value, but it hasn't mattered. I had 
 thought it might care so I tried various combinations. It in 
 this vase 
 being a nebulous entity who thwarts my plans, as to my knowledge 
 neither OJB nor Postgres care about case of table names.

Which API do you use?  Which concrete class is instantiated
for the list field?  Can you post the code that you use
to persist the objects?

Olli 

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



Re: N same class mapping question...

2003-10-14 Thread Brian McCallister
On Tuesday, October 14, 2003, at 09:33 AM, [EMAIL PROTECTED] wrote:

Hej Brian,

-Original Message-
From: Brian McCallister [mailto:[EMAIL PROTECTED]
I have mixed and matched the value, but it hasn't mattered. I had
thought it might care so I tried various combinations. It in
this vase
being a nebulous entity who thwarts my plans, as to my knowledge
neither OJB nor Postgres care about case of table names.
Which API do you use?
OTM (with OQL and Iterators instead of DLists -- see findById(...)  
below ). The project is part of my OTM learning process so I can write  
some docs on it.

 Which concrete class is instantiated
for the list field?
Default - I don't specify anything so should be a Vector.

Can you post the code that you use
to persist the objects?
Of course, I will put a tarball (  
http://kasparov.skife.org/kim-broken.tar.gz (includes jars so is big, 8  
megs)) of the whole project up, the relevent pieces:

Test Failure:
---
There was 1 failure:
1)  
testRequestFriend(org.skife.kim.model.TestUserRelations)junit.framework. 
AssertionFailedError: expected:1 but was:0
	at  
org.skife.kim.model.TestUserRelations.testRequestFriend(TestUserRelation 
s.java:76)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at  
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav 
a:39)
	at  
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor 
Impl.java:25)
	at  
com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java: 
12)
---
FAILURES!!!
Tests run: 1,  Failures: 1,  Errors: 0

The Test: (one and two are created in the setup and removed in the  
teardown)
-
public void testRequestFriend() throws Exception
{
Unit unit = Unit.begin();
one = UserRepository.findById(one.getId(), unit);
two = UserRepository.findById(two.getId(), unit);
one.addFriend(two);
unit.commit();

TestTools.clearCache();

unit = Unit.begin();
one = UserRepository.findById(one.getId(), unit);
List friends = one.getFriends();
Assert.assertEquals(1, one.getFriends().size()); // This  
Assertion Fails
unit.commit();
}
---

Unit simply provides a convenience wrapper around OTMConnections and  
Transactions:
--
package org.skife.kim.infra;

import org.apache.ojb.otm.core.Transaction;
import org.apache.ojb.otm.OTMConnection;
import org.apache.ojb.otm.kit.SimpleKit;
import org.apache.ojb.broker.PersistenceBrokerFactory;
/**
 * Unit of Work shortened for typing purposes
 *
 * TODO: Add a factory method that takes a long argument and will  
rollback the transaction
 *   after an elapsed time has passed. Each getConnection() call  
extends the time
 *   by the initial value. This allows for clearing the connection  
before the session
 *   times out in web apps
 */
public class Unit
{
private Transaction transaction;
private OTMConnection connection;

private Unit()
{
this.connection =  
SimpleKit.getInstance().acquireConnection(PersistenceBrokerFactory.getDe 
faultKey());
this.transaction =  
SimpleKit.getInstance().getTransaction(this.connection);
}

public static Unit begin()
{
Unit unit = new Unit();
unit.transaction.begin();
return unit;
}
/**
 * @throws org.skife.kim.infra.UnitException if the Unit of Work  
has already been committed
 *   or rolled back - either via this or the  
underlying
 *   Transaction/OTMConnection
 */
public void commit() throws UnitException
{
if (! transaction.isInProgress())
{
throw new UnitException(Unit of work already closed);
}
this.transaction.commit();
this.connection.close();
}

/**
 * @throws org.skife.kim.infra.UnitException if the Unit of Work  
has already been committed
 *   or rolled back - either via this or the  
underlying
 *   Transaction/OTMConnection
 */
public void rollback() throws UnitException
{
if (! transaction.isInProgress())
{
throw new UnitException(Unit of work already closed);
}
this.transaction.rollback();
this.connection.close();
}

/**
 * @return the OTMConnection in use by this Unit. It is already  
transactional
 */
OTMConnection getConnection()
{
return this.connection;
}
}

-
The findById(...) used to retrieve the User instances:
---
public static User findById(Integer id, Unit unit) throws  
UnitException
{
try
{
EnhancedOQLQuery query = unit.getConnection().newOQLQuery();
query.create(select allprofiles from 
  

RE: N same class mapping question...

2003-10-14 Thread oliver . matz
Hello Brian,

 -Original Message-
 From: Brian McCallister [mailto:[EMAIL PROTECTED]

   Which concrete class is instantiated
  for the list field?
 
 Default - I don't specify anything so should be a Vector.

I bet this is the problem.  You'd probably better
use one of the managed collections.  Could you please
check by outputting xxx.getClass().getName() somewhere? 

I do not know much about OJB's implementation of OTM,
so I can only guess from what I know about other JDO/ODMG
implementations.

see below.

  Can you post the code that you use

 The Test: (one and two are created in the setup and removed in the  
 teardown)
 -
  public void testRequestFriend() throws Exception
  {
  Unit unit = Unit.begin();
  one = UserRepository.findById(one.getId(), unit);
  two = UserRepository.findById(two.getId(), unit);
  one.addFriend(two);

If 'one' is a non-manageable collection, such as Vector, 
then 'one' does not get marked as dirty, so it won't be 
stored.

(Just a guess, maybe someelse can tell you more exactly.)

  unit.commit();
 
  TestTools.clearCache();
 
  unit = Unit.begin();
  one = UserRepository.findById(one.getId(), unit);
  List friends = one.getFriends();
  Assert.assertEquals(1, one.getFriends().size()); 
 // This  
 Assertion Fails
  unit.commit();
  }

Olli

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



Re: N same class mapping question...

2003-10-14 Thread Brian McCallister
On Tuesday, October 14, 2003, at 10:29 AM, [EMAIL PROTECTED] wrote:
I bet this is the problem.  You'd probably better
use one of the managed collections.  Could you please
check by outputting xxx.getClass().getName() somewhere?
On retrieved collections it uses:

.org.apache.ojb.broker.util.collections.RemovalAwareCollection
F
Time: 2.508

If 'one' is a non-manageable collection, such as Vector,
then 'one' does not get marked as dirty, so it won't be
stored.
(Just a guess, maybe someelse can tell you more exactly.)

On new objects it is an ArrayList, on retrieved objects a  
RemovalAwareCollection

I tried changing the collection-class to  
org.apache.ojb.broker.util.collections.ManageableArrayList but have the  
same results:

public void testRequestFriend() throws Exception
{
Unit unit = Unit.begin();
one = UserRepository.findById(one.getId(), unit);
two = UserRepository.findById(two.getId(), unit);
System.err.println(one.getFriends().getClass().getName());
one.addFriend(two);
unit.commit();
TestTools.clearCache();

unit = Unit.begin();
one = UserRepository.findById(one.getId(), unit);
List friends = one.getFriends();
System.err.println(friends.getClass().getName());
Assert.assertEquals(1, one.getFriends().size());
unit.commit();
}
-
org.apache.ojb.broker.util.collections.ManageableArrayList
org.apache.ojb.broker.util.collections.ManageableArrayList
F
Time: 2.732
There was 1 failure:
1)  
testRequestFriend(org.skife.kim.model.TestUserRelations)junit.framework. 
AssertionFailedError: expected:1 but was:0
	at  
org.skife.kim.model.TestUserRelations.testRequestFriend(TestUserRelation 
s.java:79)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at  
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.jav 
a:39)
	at  
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessor 
Impl.java:25)
	at  
com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java: 
12)

FAILURES!!!
Tests run: 1,  Failures: 1,  Errors: 0
Hmm

Using the PB API to do the same thing...

public void testRequestFriendPB() throws Exception
{
PersistenceBroker broker =  
PersistenceBrokerFactory.defaultPersistenceBroker();

Criteria tomCrit = new Criteria();
tomCrit.addEqualTo(id, one.getId());
Query tomQuery = new QueryByCriteria(User.class, tomCrit);
User tom = (User) broker.getObjectByQuery(tomQuery);
Criteria mikeCrit = new Criteria();
mikeCrit.addEqualTo(id, one.getId());
Query mikeQuery = new QueryByCriteria(User.class, mikeCrit);
User mike = (User) broker.getObjectByQuery(mikeQuery);
Assert.assertNotNull(tom);
Assert.assertNotNull(mike);
tom.addFriend(mike);
broker.store(tom);
broker.clearCache();

User tim = (User) broker.getObjectByQuery(tomQuery);

Assert.assertEquals(1, tim.getFriends().size());

broker.close();
}
Succeeds.

ODMG Implementation...

public void testRequestFriendODMG() throws Exception
{
Implementation odmg = OJB.getInstance();
Database db = odmg.newDatabase();
db.open(default, Database.OPEN_READ_WRITE);
Transaction tx = odmg.newTransaction();
tx.begin();
OQLQuery tomQuery = odmg.newOQLQuery();
tomQuery.create(select tom from  + User.class.getName() +   
where id = $1);
tomQuery.bind(one.getId());
DList results = (DList) tomQuery.execute();
User tom = (User) results.iterator().next();

OQLQuery mikeQuery = odmg.newOQLQuery();
mikeQuery.create(select mike from  + User.class.getName() +   
where id = $1);
mikeQuery.bind(two.getId());
results = (DList) mikeQuery.execute();
User mike = (User) results.iterator().next();

tom.addFriend(mike);
tx.commit();
PersistenceBroker broker =  
PersistenceBrokerFactory.defaultPersistenceBroker();
broker.clearCache();
broker.close();

tx = odmg.newTransaction();
tx.begin();
OQLQuery timQuery = odmg.newOQLQuery();
timQuery.create(select tom from  + User.class.getName() +   
where id = $1);
timQuery.bind(one.getId());
results = (DList) timQuery.execute();
User tim = (User) results.iterator().next();

Assert.assertEquals(1, tim.getFriends().size());

tx.commit();
}
Also succeeds.

The explicit OTM implementation..

public void testRequestFriendOTM() throws Exception
{
OTMConnection conn =  
SimpleKit.getInstance().acquireConnection(PersistenceBrokerFactory.getDe 
faultKey());
org.apache.ojb.otm.core.Transaction tx =  
SimpleKit.getInstance().getTransaction(conn);
tx.begin();
EnhancedOQLQuery tomQuery = conn.newOQLQuery();
tomQuery.create(select tom from  + 

Re: N same class mapping question...

2003-10-14 Thread Brian McCallister
Follow up.. Changing the OTM Test to use PB style QueryByCriteria also  
fails:

public void testRequestFriendOTMTwo() throws Exception
{
OTMConnection conn =  
SimpleKit.getInstance().acquireConnection(PersistenceBrokerFactory.getDe 
faultKey());
org.apache.ojb.otm.core.Transaction tx =  
SimpleKit.getInstance().getTransaction(conn);
tx.begin();

Criteria tomCrit = new Criteria();
tomCrit.addEqualTo(id, one.getId());
Query tomQuery = new QueryByCriteria(User.class, tomCrit);
Criteria mikeCrit = new Criteria();
mikeCrit.addEqualTo(id, two.getId());
Query mikeQuery = new QueryByCriteria(User.class, mikeCrit);
User tom = (User) conn.getIteratorByQuery(tomQuery).next();
User mike = (User) conn.getIteratorByQuery(mikeQuery).next();
tom.addFriend(mike);
tx.commit();
conn.close();
PersistenceBroker broker =  
PersistenceBrokerFactory.defaultPersistenceBroker();
broker.clearCache();
broker.close();

conn =  
SimpleKit.getInstance().acquireConnection(PersistenceBrokerFactory.getDe 
faultKey());
tx = SimpleKit.getInstance().getTransaction(conn);
tx.begin();

Criteria timCrit = new Criteria();
timCrit.addEqualTo(id, one.getId());
Query timQuery = new QueryByCriteria(User.class, timCrit);
User tim = (User) conn.getIteratorByQuery(timQuery).next();

Assert.assertEquals(1, tim.getFriends().size());

tx.commit();
conn.close();
}
-Brian

On Tuesday, October 14, 2003, at 11:39 AM, Brian McCallister wrote:

On Tuesday, October 14, 2003, at 10:29 AM, [EMAIL PROTECTED] wrote:
I bet this is the problem.  You'd probably better
use one of the managed collections.  Could you please
check by outputting xxx.getClass().getName() somewhere?
On retrieved collections it uses:

.org.apache.ojb.broker.util.collections.RemovalAwareCollection
F
Time: 2.508

If 'one' is a non-manageable collection, such as Vector,
then 'one' does not get marked as dirty, so it won't be
stored.
(Just a guess, maybe someelse can tell you more exactly.)

On new objects it is an ArrayList, on retrieved objects a  
RemovalAwareCollection

I tried changing the collection-class to  
org.apache.ojb.broker.util.collections.ManageableArrayList but have  
the same results:

public void testRequestFriend() throws Exception
{
Unit unit = Unit.begin();
one = UserRepository.findById(one.getId(), unit);
two = UserRepository.findById(two.getId(), unit);
System.err.println(one.getFriends().getClass().getName());
one.addFriend(two);
unit.commit();
TestTools.clearCache();

unit = Unit.begin();
one = UserRepository.findById(one.getId(), unit);
List friends = one.getFriends();
System.err.println(friends.getClass().getName());
Assert.assertEquals(1, one.getFriends().size());
unit.commit();
}
-
org.apache.ojb.broker.util.collections.ManageableArrayList
org.apache.ojb.broker.util.collections.ManageableArrayList
F
Time: 2.732
There was 1 failure:
1)  
testRequestFriend(org.skife.kim.model.TestUserRelations)junit.framework 
.AssertionFailedError: expected:1 but was:0
	at  
org.skife.kim.model.TestUserRelations.testRequestFriend(TestUserRelatio 
ns.java:79)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at  
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja 
va:39)
	at  
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso 
rImpl.java:25)
	at  
com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java 
:12)

FAILURES!!!
Tests run: 1,  Failures: 1,  Errors: 0
Hmm

Using the PB API to do the same thing...

public void testRequestFriendPB() throws Exception
{
PersistenceBroker broker =  
PersistenceBrokerFactory.defaultPersistenceBroker();

Criteria tomCrit = new Criteria();
tomCrit.addEqualTo(id, one.getId());
Query tomQuery = new QueryByCriteria(User.class, tomCrit);
User tom = (User) broker.getObjectByQuery(tomQuery);
Criteria mikeCrit = new Criteria();
mikeCrit.addEqualTo(id, one.getId());
Query mikeQuery = new QueryByCriteria(User.class, mikeCrit);
User mike = (User) broker.getObjectByQuery(mikeQuery);
Assert.assertNotNull(tom);
Assert.assertNotNull(mike);
tom.addFriend(mike);
broker.store(tom);
broker.clearCache();

User tim = (User) broker.getObjectByQuery(tomQuery);

Assert.assertEquals(1, tim.getFriends().size());

broker.close();
}
Succeeds.

ODMG Implementation...

public void testRequestFriendODMG() throws Exception
{
Implementation odmg = OJB.getInstance();
Database db = odmg.newDatabase();
db.open(default, Database.OPEN_READ_WRITE);
Transaction tx = 

M:N same class mapping question...

2003-10-12 Thread Brian McCallister
I am having problems getting a class to properly persist collections of 
instances of the same class (see configs later in the email). Using the 
M:N mapping seems to be the way to do this, but it isn't actually 
working. If the relations exist in the database the data loads fine, 
however it doesn't seem to want to persist new instances to the M:N 
table. I am using the non-decomposed style M:N and have tried with the 
mapping listed below, and the auto-update and auto-retrieve removed 
with no change in behavior.

Anyone see what is wrong with the code below?

-- OJB Mapping ---

class-descriptor class=test.User table=USERS
field-descriptor name=id column=ID jdbc-type=INTEGER 
primarykey=true autoincrement=true/

collection-descriptor name=friends 
element-class-ref=org.skife.kim.model.User
indirection-table=USER_FRIEND
auto-retrieve=true
auto-update=true

fk-pointing-to-this-class column=user_id/
fk-pointing-to-element-class column=friend_id/
/collection-descriptor
/class-descriptor

-- Schema Def'n --

table name=user_friend description=M:N mapping table for user's 
friends
column name=user_id primaryKey=true type=INTEGER 
description=User ID /
column name=friend_id primaryKey=true type=INTEGER 
description=User ID /

foreign-key foreignTable=users
reference local=user_id foreign=id/
/foreign-key
foreign-key foreignTable=users
reference local=friend_id foreign=id/
/foreign-key
/table
-- Class --

public class User
{
List friends;
}
Friends contains User instances. It seems that it loads classes 
properly if they are already in the database, but is not inserting new 
relations.

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


Re: M:N same class mapping question...

2003-10-12 Thread Brian McCallister
Note that the package names *do* match in the actual code - Changed the 
one in place in the email and not the other =)

-Brian

On Sunday, October 12, 2003, at 10:38 PM, Brian McCallister wrote:

I am having problems getting a class to properly persist collections 
of instances of the same class (see configs later in the email). Using 
the M:N mapping seems to be the way to do this, but it isn't actually 
working. If the relations exist in the database the data loads fine, 
however it doesn't seem to want to persist new instances to the M:N 
table. I am using the non-decomposed style M:N and have tried with the 
mapping listed below, and the auto-update and auto-retrieve removed 
with no change in behavior.

Anyone see what is wrong with the code below?

-- OJB Mapping ---

class-descriptor class=test.User table=USERS
field-descriptor name=id column=ID jdbc-type=INTEGER 
primarykey=true autoincrement=true/

collection-descriptor name=friends 
element-class-ref=org.skife.kim.model.User
indirection-table=USER_FRIEND
auto-retrieve=true
auto-update=true

fk-pointing-to-this-class column=user_id/
fk-pointing-to-element-class column=friend_id/
/collection-descriptor
/class-descriptor

-- Schema Def'n --

table name=user_friend description=M:N mapping table for 
user's friends
column name=user_id primaryKey=true type=INTEGER 
description=User ID /
column name=friend_id primaryKey=true type=INTEGER 
description=User ID /

foreign-key foreignTable=users
reference local=user_id foreign=id/
/foreign-key
foreign-key foreignTable=users
reference local=friend_id foreign=id/
/foreign-key
/table
-- Class --

public class User
{
List friends;
}
Friends contains User instances. It seems that it loads classes 
properly if they are already in the database, but is not inserting new 
relations.

Danke,
Brian


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