Code:
session.saveOrUpdate(review); //tried save and update sep.
session.saveOrUpdate(review.getState()); //added out of desperation.
session.flush();
session.connection().commit();
Mapping:
Code:
<class name="Review" table="review">
<id name="id" type="long" column="review_id">
<generator class="identity"/>
</id>
<one-to-one name="state" class="ReviewState" cascade="all"/>
...
<class name = "ReviewState" table="review_state">
<id name="id" type="long" column="review_id">
<generator class="foreign">
<param name="property">review</param>
</generator>
</id>
<one-to-one name="review" class="Review" constrained="true"/>
...
The Review is created with an initialized ReviewState object, but the
ReviewState object's Review is null (and resulted in an exception).
Adding this weirdness at creation fixed that:
Code:
//associate the review with the state.
review.getState().setReview(review);
Now, when the review is changed and saved, changes persist, but when
the ReviewState is changed, changed do not. show_sql doesn't generate any SQL. If a review is created or deleted, the corresponding reviewstate is inserted or deleted. I've set breakpoints and stepped thru to ensure that the expected values are indeed what is expected, and they are. On load, the value is 0, right before save and after the value is 3, but in the
db, the value remains 0. What do I need to change to make this persist
the changes - as the code shows, I've tired saving the ReviewState explicitly, and nothing.