Unfortunately, removing inverse="true" does not help.
Here is my PartnerContent.hbm.xml
<hibernate-mapping>
<class
name="xxx.partner.model.PartnerContent"
table="PARTNER_CONTENT"
>
<composite-id name="comp_id" class="xxx.partner.model.PartnerContentPK">
<key-property
name="partnerId"
column="PARTNERID"
type="java.lang.Long"
length="10"
/>
<key-property
name="contentId"
column="CONTENT_ID"
type="java.lang.Long"
length="10"
/>
</composite-id>
...
Partner.hbm.xml has mapping with partnercontent as below:
<set
name="partnerContents"
lazy="true"
cascade="all-delete-orphan"
>
<key>
<column name="PARTNERID" />
</key>
<one-to-many
class="xxx.partner.model.PartnerContent"
/>
</set>
Partner.java has
public void addPartnerContent(PartnerContent partnerContent) {
partnerContent.setPartner(this);
this.getPartnerContents().add(partnerContents);
}
populatePartnerwithContent() {
PartnerContent pcBean = PartnerContent();
PartnerContentPK pcPK = new PartnerContentPK();
pc.setPartnerId(this.getPartnerId());
pc.setContentId(smallLogoContent.getContentId());
pcBean.setComp_id(partnerContentPK);
pcBean.setContent(contentBean);
this.addPartnerContent(pcBean);
}
public class PartnerContentPK implements Serializable {
/** identifier field */
private Long partnerId;
/** identifier field */
private Long contentId;
/** full constructor */
public PartnerContentPK(Long partnerId, Long contentId) {
this.partnerId = partnerId;
this.contentId = contentId;
}
/** default constructor */
public PartnerContentPK() {
}
public Long getPartnerId() {
return this.partnerId;
}
public void setPartnerId(Long partnerId) {
this.partnerId = partnerId;
}
public Long getContentId() {
return this.contentId;
}
public void setContentId(Long contentId) {
this.contentId = contentId;
}
public String toString() {
return new ToStringBuilder(this)
.append("partnerId", getPartnerId())
.append("contentId", getContentId())
.toString();
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( !(other instanceof PartnerContentPK) ) return false;
PartnerContentPK castOther = (PartnerContentPK) other;
return new EqualsBuilder()
.append(this.getPartnerId(), castOther.getPartnerId())
.append(this.getContentId(), castOther.getContentId())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getPartnerId())
.append(getContentId())
.toHashCode();
}
}
/** @author Hibernate CodeGenerator */
public class PartnerContent implements Serializable {
/** identifier field */
private PartnerContentPK comp_id;
/** persistent field */
private Content content;
/** nullable persistent field */
private Partner partner;
...constructors and getters/setters
}
Exception looks like:
08 Mar 2006 11:40:54,189 ERROR (org.hibernate.util.JDBCExceptionReporter:58) - ORA-01400: cannot insert NULL into ("CUADMIN"."PARTNER_CONTENT"."PARTNERID")
08 Mar 2006 11:40:54,199 ERROR (org.hibernate.event.def.AbstractFlushingEventListener:277) - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:179)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:72)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:67)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:148)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1848)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2209)
.....
|