-
1. Re: Injecting and persisting entity and relations
kragoth Mar 3, 2009 6:42 AM (in response to troy.sellers)Ok to fix your persisting problem try using cascade (read the doco on this to get the full info on it). But for example where you have the @OneToOne annotaion you would put.
@OneToOne(cascade = { CascadeType.ALL })
What this means is that when you persist your Form entity it will persist the customerDetails entity.
There is a possibility that this isn't what you want but from what you have said so far it would appear to me that it would be your solution.Your other problem can be solved the way the SEAM examples show.
If you look in the SEAM booking example you will see in the HotelBookingAction.java@In(required=false) @Out(required=false) private Booking booking;
public void bookHotel() { booking = new Booking(hotel, user); Calendar calendar = Calendar.getInstance(); booking.setCheckinDate( calendar.getTime() ); calendar.add(Calendar.DAY_OF_MONTH, 1); booking.setCheckoutDate( calendar.getTime() ); }
What this means is that when the bookHotel method is called (presumably from a create booking button) a new Booking entity is created (hotel and user are set earlier). Once this entity is created and the method invocation is finished the booking variable is outjected and is now accessable via the @In.
The seam examples are a really good place to get to understand the more fundamental ideas that SEAM is based on. Take some time to go through them all it will help a lot! :D
-
2. Re: Injecting and persisting entity and relations
troy.sellers Mar 5, 2009 2:51 AM (in response to troy.sellers)Hi Tim.
Thanks for the tips. Using the Cascade elements worked a treat.
I am not sure what you meant with the example from Hotel Booking however. If I built the entity and then Outjected, would this work in a similar method to Cascade?
The child entities in my case are created at the same time as the parent. The parent is created using @In(create=true) yet this doesn't create the children, so I also inject child objects into the same action (again using create=true) and build them into the parent manually.
Is there a means of creating the parent so that these OneToOne related objects are also created?
Cheers,
Troy