Entity with private key - not-null property references a null or transient value
bsgcic May 20, 2010 2:16 PMCan someone help me with this error? I have been searching for solutions to this problem to no avail. I am trying to add to a table which has an embedded private key.
I get the following error:
not-null property references a null or transient value
Here is the persist code:
contactFormsLocale.setContactFormsLocalePK(new ContactFormsLocalePK(contactForm, userSettings.getViewLocale())); entityManager.persist(contactFormsLocale);
Portions of the embeddable ContactFormsLocalePK class:
@Embeddable public class ContactFormsLocalePK implements Serializable private ContactForm contactForm; private Locale locale; public ContactFormsLocalePK() {} public ContactFormsLocalePK(ContactForm contactForm, Locale locale) { this.contactForm = contactForm; this.locale = locale; } @ManyToOne @NotNull @JoinColumn(name="contactFormAutoIdInt", insertable=true, updatable=true) public ContactForm getContactForm() { return contactForm; } public void setContactForm(ContactForm contactForm) { this.contactForm = contactForm; } @ManyToOne @NotNull @JoinColumn(name="localeAutoIdInt", insertable=true, updatable=true) public Locale getLocale() { return locale; } public void setLocale(Locale locale) { this.locale = locale; } @Override public int hashCode() { return (int) contactForm.hashCode() + locale.hashCode(); } @Override public boolean equals(Object obj) { if (obj == this) return true; if (!(obj instanceof ContactFormsLocalePK)) return false; if (obj == null) return false; ContactFormsLocalePK pk = (ContactFormsLocalePK) obj; return pk.contactForm == contactForm && pk.locale == locale; }
Portions of the embeddable ContactFormsLocale class:
@EmbeddedId public ContactFormsLocalePK getContactFormsLocalePK() { return contactFormsLocalePK; } public void setContactFormsLocalePK(ContactFormsLocalePK contactFormsLocalePK) { this.contactFormsLocalePK = contactFormsLocalePK; } @Transient public ContactForm getContactForm() { return contactFormsLocalePK.getContactForm(); } @Transient public Locale getLocale() { return contactFormsLocalePK.getLocale(); } @NotNull @SequenceGenerator(name="contactFormsLocales_automaticNumberInt_seqIdentifier", sequenceName="contactformslocales_automaticnumberint_seq", allocationSize=1) @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="contactFormsLocales_automaticNumberInt_seqIdentifier") @Column(name="automaticNumberInt", unique=true, columnDefinition="bigserial") public Long getId() { return id; } public void setId(Long id) { this.id = id; }
Portions of the embeddable ContactForm class:
public ContactForm() {} public ContactForm(Long id) { this.id = id; } @Id @NotNull @SequenceGenerator(name="contactForms_automaticNumberInt_seqIdentifier", sequenceName="contactforms_automaticnumberint_seq", allocationSize=1) @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="contactForms_automaticNumberInt_seqIdentifier") @Column(name="automaticNumberInt", unique=true, columnDefinition="bigserial") public Long getId() { return id; } public void setId(Long id) { this.id = id; } @Column(name="emailStr") public String getEmailStr() { return emailStr; } public void setEmailStr(String emailStr) { this.emailStr = emailStr; }
Any help or thoughts would be greatly appreciated.
Thanks,
Jeff