I'm not clear on what your saveOrUpdate methods are doing -- can you share
this?
> //save newLauncher before adding it to timeline
> newLauncher.saveOrUpdate(); //this performs an opensession,
> saveOrUpdate(newLauncher), then closesession
I suspect that when you save/update the timeline the second time in a
separate session, that you're losing the relationship.
try this:
timeline.addLauncher(newLauncher);
newLauncher.saveOrUpdate(); // these two lines seem like they do the same
thing
saveOrUpdate(newLauncher);
// then throw away the timeline.saveOrUpdate lines below:
// timeline.saveOrUpdate(); //this performs an opensession,
// saveOrUpdate(newLauncher), then closesession
perhaps you can have a dao that saves the launcher w/ a signature like:
void saveLauncher(Launcher newLauncher) throws DaoException; //performs a
save or update on the launcher where launcher has a relationship back to
timeline? this should save the new launcher and the foreignkey back to
timeline.
// if the timeline object is dirty, I'm not positive (but I'm pretty
sure), but I believe it will be saved as well.
p.s. an executable, compilable test case is helpful when trying to
isolate these problems and include whatever simple domain objects are
needed (launcher/timeline)
Trey Howard <trey.howard@xxxxxxxxxxxxxxxx> wrote on 09/17/2004 11:40:38
AM:
> Here's a snippet of a test case that shows the order of what I'm trying
> to do.
>
>
> Launcher newLauncher = new Launcher();
> newLauncher.setParentModel(timeline);
> newLauncher.setSource(source);
> newLauncher.setTarget(target);
>
> //save newLauncher before adding it to timeline
> newLauncher.saveOrUpdate(); //this performs an opensession,
> saveOrUpdate(newLauncher), then closesession
>
> //add newLauncher to timeline
> timeline.addLauncher(newLauncher);
>
> //we need to save timeline after adding newLauncher
> timeline.saveOrUpdate(); //this performs an opensession,
> saveOrUpdate(newLauncher), then closesession
>
> log.debug("Launcher object created: " + newLauncher); //prints: Launcher
> object created:
>
Launcher[id=6,timelineId=7,sourceId=15,targetId=16,offset=0.0,offsetEnd=true]
>
> newLauncher = (Launcher) newLauncher.connector().findByPK(
> newLauncher.getId());
>
> log.debug("after reloading from db:");
> log.debug("newLauncher = " + newLauncher); //prints: newLauncher =
> Launcher[id=6,timelineId=notimeline,sourceId=15,targetId=16,
> offset=0.0,offsetEnd=true]
>
>
> Note: the 'notimeline' for the timelineId results from not having a
> parentTimeline
> Here's Launcher.toString():
> public String toString() {
> StringBuffer retval = new StringBuffer(30);
> retval.append("Launcher[");
> retval.append("id=");
> retval.append(id);
> retval.append(",timelineId=");
> retval.append(parentModel != null ?
parentModel.getId().toString()
> : "notimeline");
> retval.append(",sourceId=");
> retval.append(source != null ? source.getId().toString() :
> "nosource");
> retval.append(",targetId=");
> retval.append(target != null ? target.getId().toString() :
> "notarget");
> retval.append(",offset=");
> retval.append(offset);
> retval.append(",offsetEnd=");
> retval.append(offsetEnd);
> retval.append("]");
>
> return retval.toString();
> }
>
> I have not yet researched the hibernate forums. I will pursue this in
> the meantime.
>
> -Trey
>
>
> Brian K Bonner wrote:
>
> >Hey Trey,
> >
> >Verify that you are setting the timeline on the Launcher prior to the
> >save? Is the launcher added to the timeline set?
> >
> >1. provide a snippet of the test case that exhibits this behavior
> >(between your opensession and closesession)
> >2. enable debug in log4j to see if that helps identify the problem.
> >
> >Post both 1 and 2 to provide us additional clues.
> >
> >Did you check forum.hibernate.org?
> >
> >Brian
> >
> >
> >Trey Howard <trey.howard@xxxxxxxxxxxxxxxx> wrote on 09/16/2004 04:17:51
> >PM:
> >
> >
> >
> >>Hi All
> >>
> >>I'm having a problem with getting a hibernate mapping to work.
> >>
> >>I have a parent, class Timeline, that has children, class Launcher.
> >>
> >>Here is the xdoclet hibernate mapping in Timeline for the Launcher set
> >>@hibernate.set table="timeline_launcher" cascade="none"
> >>@hibernate.collection-key column="parent_timeline"
> >>@hibernate.collection-one-to-many class="fqns.Launcher"
> >>
> >>Here is the xdoclet hibernate mapping in Launcher for the parent
> >>
> >>
> >Timeline
> >
> >
> >>@hibernate.collection-key column="parent_timeline"
> >>@hibernate.collection-many-to-one class="fqns.Timeline"
> >>
> >>
> >>The problem is that when I retrieve a child Launcher instance, the
field
> >>
> >>
> >
> >
> >
> >>for the parent Timeline shows null, whereas the database shows the
> >>correct value.
> >>For instance:
> >>I have a Timeline id=1 and create a new Launcher and .saveOrUpdate()
it
> >>to give it an id of 4.
> >>The Launcher (POJO) will return that its parent Timeline is 1 (this is
> >>what's in the database, also).
> >>However, if I then perform a .load(4), the Launcher (POJO) will return
a
> >>
> >>
> >
> >
> >
> >>null parent Timeline.
> >>
> >>So, it appears as though I can save the parent-child relationship, but
I
> >>
> >>
> >
> >
> >
> >>can't retrieve it.
> >>Do I need to specify an option to one of the above mappings to achieve
> >>the functionality I described?
> >>
> >>In case it matters, I'm running MySQL 3.23.58
> >>
> >>Any help would be appreciated!
> >>-Trey
> >>
> >>
> >>---------
> >>You may unsubscribe from this mailing list
> >>by sending a blank email addressed to:
> >>users-unsubscribe@xxxxxxxxxx
> >>
> >>--
> >>Find additional help by sending a blank email
> >>addressed to:
> >>users-help@xxxxxxxxxx
> >>
> >>
> >>
> >
> >
> >---------
> >You may unsubscribe from this mailing list
> >by sending a blank email addressed to:
> >users-unsubscribe@xxxxxxxxxx
> >
> >--
> >Find additional help by sending a blank email
> >addressed to:
> >users-help@xxxxxxxxxx
> >
> >
> >
> >
>
> ---------
> You may unsubscribe from this mailing list
> by sending a blank email addressed to:
> users-unsubscribe@xxxxxxxxxx
>
> --
> Find additional help by sending a blank email
> addressed to:
> users-help@xxxxxxxxxx
>
|