Context: 1) We're newbies. 2) We're mapping two entities, Order & ContactInfo. Order has a reference to ContactInfo. Many different Orders can reference the same ContactInfo, i.e. it's a many-to-one relationship. We use Oracle 10g and sequences for our primary keys. As such, we used the following generator configuration:
<generator class="org.hibernate.id.enhanced.SequenceStyleGenerator"> <param name="sequence_name">ORDER_INFO_SEQ</param> </generator>
However, we found that when we save a new Order instance, this causes a SELECT to be performed on the sequence in order to get a new PK, and then an INSERT performed with that new PK. We later discovered that we could inline the call to get the next value of the sequence inside of the INSERT statement if we switched the generator to the following:
<generator class="sequence-identity"> <param name="sequence">ORDER_INFO_SEQ</param> </generator> However, when we do that it appears that our cascade="persist, merge, save-update" on the Order to ContactInfo relationship no longer works. Instead we see the following exception:
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.acme.entity.OrderInfo.userContactInfo
By the cascade no longer working the use case that causes this behavior is essentially:
--start Tx Order o = new Order(); ContactInto c = new ContactInfo(); o.setContactInfo(c); getSession().save(o); --end Tx
Does anyone have an explanation for this behavior or is this possibly a bug?
Thanks, O
|