Back Forum Reply New

not-null property references a null or transient value

Hi guys,

I am using latest versions of Spring and Hibernate + JOTM
Have a problem when I try to persist a parent/child entity inside a transaction. Getting exception : org.hibernate.PropertyValueException: not-null property references a null or transient value: com.Child.parent  My entity beans :

Child:

@Entity
@Table(name = quot;Childquot;)
public class Child implements Serializable {
   @Id   @GeneratedValue(strategy = GenerationType.AUTO)   private Long id;
   private Double value;
   @ManyToOne   @JoinColumn(name = quot;parentIdquot;, nullable = false)   protected Parent parent;
}

Parent:

@Entity
@Table(name = quotarentquot;)
public class Parent implements Serializable {
   @Id   private String id;   @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}, mappedBy = quot;parentquot;)   private Setlt;Childgt; children;
}

And I save them inside a transaction :
@Transactional   public void doUpdate(Parent parent) throws Exception {       JpaTemplate template = getJpaTemplate();
       template.merge(parent);      
}

The problem is that if parent already exists code will work fine. If parent does not exists I am getting abovementioned exception. I found a workaround :

1. Set     @JoinColumn(name = quot;parentIdquot;, nullable = true), i.e. true instead of false, that seems completely stupid as parent is never null actually
2. Prepersist parent in different transaction first

It seems like it is a transactional issue as I remember when I was using application-managed transactions, like transaction.begin(commit) i did not experience this.

Could someone please help me with this issue?

Ok, no worries guys. It was not about Spring, it was all about jotm version i used (2.0.10).
I got the jotm libraries from Spring distribution and everthing seems to be fine now: I do not need to prepersist and may have nullable = false
¥
Back Forum Reply New