Yes, I think it is backwards myself.
 
I made the change and the Parent record got inserted. This is my first inserted record 
so far using OJB, after over two weeks of trying.
 
Unfortunately, the child record never got inserted.
 
Back after 1 hour.
 
Here is what I did to make it insert into both tables. Here is my insert method of my 
DAO object
 
public void insert(ValueObject insertRecord) throws DataAccessException {
        log.info("************Entering the TourDAO.insert***************");
        PersistenceBroker broker = null;
        try {
            broker = ServiceLocator.getInstance().findBroker();
            TourVO tour = (TourVO)insertRecord;
            AssumptionVO assumptionVO = tour.getAssumptions();
            broker.beginTransaction();
            broker.store(tour);
            assumptionVO.setTour(tour);
            broker.store(assumptionVO);            
            broker.commitTransaction();
      .......
     
Of course the other remaining code is just the catch and finally parts.
 
I thought that OJB was set up that it would have automatically saves the child record, 
instead of me having to call store() a second time on the broker.
 
But I am happy that I got the records inserted, I can finally move on in my project to 
the next steps. As I had said I have been stuck trying to get OJB to work for over two 
weeks, and this is a simple project I wrote.
 
Thanks for you help.
 
Mark

"McCaffrey, John G." <[EMAIL PROTECTED]> wrote:

yes, (my understanding) if you have a 1-1 relationship, but there is a FK
constraint that indicates a parent > child relationship, then OJB wants the
Child Mapping to contain a reference to the parent. 

I think the basic rule is like this
mapping for Object A
contains 
ref to B
ref to C
collection ref to D

SQL queries will go like this
insert B
insert C
insert A
insert D

That was a suprise to me, and I wish it wasn't like that. (I have asked if I
am just not understanding this, but i haven't gotten a response that says I
am wrong yet)

What I don't like about it is that if you have a 1-1 child relationship you
have to invert you mapping to make OJB happy, but it might not make sense
for yuo object

ex (this is what I would like to do):
company obj mapping (parent)
contains
primary manager obj (only one reference and this is truly a child of
company)
primary address obj (same deal)

but this would fail because OJB will try to insert the manager and address
first
instead I think you have to do this:

Manager
contains 
a company
(I don't even know what will happen with the address)

So if I am understanding this, it really makes it hard for you to use
composite VOs when you have 1-1 parent-child relationships.

any thoughts? (someone please tell me that I am wrong, and that there is a
better way to do this)



-----Original Message-----
From: Mark Spritzler [mailto:[EMAIL PROTECTED]
Sent: Friday, May 07, 2004 4:21 PM
To: OJB Users List
Subject: RE: Child Table insert at same time as Parent and Auto
generated PK


Hi John, thanks. Actually I have already added the sequence manager to the
jdbc-connection-descriptor, and also the settings for the primary key.

So are you saying that my reference-descriptor in the Parent table needs to
be removed and instead add it to my child table? If not then, what do you
mean. :)

Thanks

Mark

"McCaffrey, John G." wrote:
Search the archives for SequenceManger and Idenity threads.

Here is what I needed to do:
add a sequence manager to my jdbc-connection-descriptor
className="org.apache.ojb.broker.util.sequence.SequenceManagerNativeImpl">


Make sure these were set on my primary key
primarykey="true"
autoincrement="true"
access="readonly"

Then I had to flip my mapping because I had
Parent > contains a reference to a single Child (not a collection)
but OJB wants Child > contains reference to Parent

HTH

-----Original Message-----
From: Mark Spritzler [mailto:[EMAIL PROTECTED]
Sent: Friday, May 07, 2004 4:05 PM
To: [EMAIL PROTECTED]
Subject: Child Table insert at same time as Parent and Auto generated PK


I am using MySql.

OK. I have a Parent-Child relationship which is 1:1 relationship. I am
inserting into each table at the same time. Obviously, the Parent gets
inserted first. But the Primary Key is auto-generated by MySQL in an
auto-generated field. So when the child record gets inserted, I need that
newly created ID to be in the child record. But it isn't getting it, and the
ID in the child is Null, so the Database returns an error for it being Null.

Does anyone know a way to fix this problem? Putting the child fields into
the Parent table is not a possibility and wouldn't be a good db design
decision.

Thanks everyone

Mark


---------------------------------
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs 

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



Franziska says, "Keep eating healthy"

she also says that the above line is not actually gramatically correct. 

She wants you all to know that healthy cannot be there; it really should be
an adverb like healthfully.


---------------------------------
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs 

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

                
---------------------------------
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs 

Reply via email to