----- Original Message -----
Sent: Tuesday, October 07, 2003 12:17
PM
Subject: Re: [Hibernate] relationship not
getting saved
What you did was created mapping file
first and from it you created the Class files
I did exactly opposite I created the
class files through poseidon first and then created mapping file for
it.
You can choose anyway you
like.
just specify
'inverse=true'
your class would be looking like
this
public class Workspace{
private list asset;
file://getter and setters would alway be for this variable
public void
addAsset(Asset _asset){
if(asset==null)asset=new ArrayList();
asset.add(_asset);
_asset.setWorkspace(this);
}
}
public class Asset{
private Workspace
workspace;//getter and setters would always be for this variable
}
This code should do the job for
you
But relationship has to go two
ways. When you say session.save(workspace) it should save every
association.
regards & all the best
prasad chandrasekaran
----- Original Message -----
Sent: Monday, October 06, 2003 8:37
PM
Subject: Re: [Hibernate] relationship
not getting saved
> Thank you prasad for
your quick response.
>
> I think this should work
two-way.
>
>
> 1) I create WorkLocation object first and
save it. And I create Asset
> object.
> then I
set _asset.setWorkLocation(_workLocation).
> Then I
call _session.save(_asset). This will save the asset and the
>
association.
> 2)I create Asset and save it. And I create WorkLocation
object. Then I will
> add the _asset
>
to_workLocation.
> public void addAsset(_asset) {
>
asset.add(_asset);
>
}
> Then I will call _session.save(_workLocation). This
should save
> WorkLocation and the
> association,
which is not happening.
>
> Why there is a
difference? when many-to-one class can save the
> association, why
not
> one-to-many class can save the association without
setting it explicitly.
>
>
> I have one more question from
your response. I generated the classes from
> mapping file.
> But
the generated class WorkLocation did not have the addAsset() method in
>
it. Should
> I add anything to mapping to generate that method?.
>
>
> thanks
> Dosapati
>
> ----- Original
Message -----
> From: "Prasad Iyer" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Monday, October 06, 2003 7:52
PM
> Subject: Re: [Hibernate] relationship not getting saved
>
>
> > There is a problem in your bean.
> > please
check for this code.
> > Every object of Asset in the Collection
should in turn have the
> relationship
> > with the
WorkLocation.
> > That is you might have got function like this in
WorkLocation
> >
> > public void addAsset(Asset
_asset){
> > asset.add(_asset);
>
> _asset.setWorkLocation(this);
> >
}
> > otherwise before saving you would have to iterate through the
collection
> of
> > asset.
> > And set
> >
_asset.setWorkLocation(workLocation);
> >
> > where asset is
some collection (List, Set, Map)
> > regards
> > prasad
chandrasekaran
> >
> >
> >
> >
>
> ----- Original Message -----
> > From: "dosapati" <[EMAIL PROTECTED]>
> > To: <[EMAIL PROTECTED]>
> > Sent: Monday, October 06, 2003
6:56 PM
> > Subject: [Hibernate] relationship not getting
saved
> >
> >
> > > I dont know wheteher I can
post this question here or not. Please let me
> > > know if there
is any other users group.
> > >
> > > I am facing this
problem with one-to-many association.
> > >
> > >
association is not getting saved with one-to-many relation class, but
it
> > is
> > > getting saved with many-to-one relation
class.
> > >
> > > Example: WorkLocation - to - Asset
is one-to-many. And Asset - to -
> > > WorkLocation is many-to-one
relation.
> > > When An Asset entity is set with WorkLocation
object and the Asset is
> > saved,
> > > the association
Asset-to-WorkLocation is getting saved.
> > > when a Collection of
Assets is set to WorkLocation object and the
> > > WorkLocation
object is saved, the association Asset-to-WorkLocation is
> not
>
> > getting saved.
> > >
> > > thanks
>
> > Dosapati
> > >
> > >
> >
>
> > >
-------------------------------------------------------
> > > This
sf.net email is sponsored by:ThinkGeek
> > > Welcome to geek
heaven.
> > > http://thinkgeek.com/sf
> > >
_______________________________________________
> > >
hibernate-devel mailing list
> > > [EMAIL PROTECTED]
> > > https://lists.sourceforge.net/lists/listinfo/hibernate-devel
> >
> >
> >
> >
-------------------------------------------------------
> > This
sf.net email is sponsored by:ThinkGeek
> > Welcome to geek
heaven.
> > http://thinkgeek.com/sf
> >
_______________________________________________
> > hibernate-devel
mailing list
> > [EMAIL PROTECTED]
> > https://lists.sourceforge.net/lists/listinfo/hibernate-devel
>
>
>
>
-------------------------------------------------------
> This sf.net
email is sponsored by:ThinkGeek
> Welcome to geek heaven.
>
http://thinkgeek.com/sf
> _______________________________________________
>
hibernate-devel mailing list
> [EMAIL PROTECTED]
> https://lists.sourceforge.net/lists/listinfo/hibernate-devel