views:

98

answers:

1

I have an entity A who has entity B.

Class Entity A
{
    public EntityB;
}

Class Entity B
{
    public Entity A;
}

Entity B has one to one relationship with A. I am trying to use cascade save,delete when entity A is saved so that I don't have to manually save entity B. It shpould be done automatically.

my mapping for entity B looks like:

<many-to-one name="EntityA" cascade="save-update"
    column="EntityASomeProperty" class="EntityA" />

I not able to save entity B automatically when A is saved.

A: 

It looks like you have a cascade defined from B to A, so that when you save EntityB, EntityA should be saved.

If you want EntityB saved when you save EntityA, you'll need to have that configuration reversed. Note that you should pick a direction in which you want to manage this relationship and always work from that direction. You can map both directions, but make one inverse so that hibernate knows which direction you intend to manage it from.

I'd also suggest you use a OneToOne mapping, if that is what it really is.

Brian Yarger
Hi i got your point. But my next question is after creating one-to-one mapping on entityA which would save Entity B im getting an error that cannot insert null into ENtityB one of the column.And that column contains the entityA property(ENtityA Guid).
alice7