Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

org.hibernate.PropertyValueException: not-null property references a null or transien

$
0
0
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.xxx.Child.parent

I am trying to save the parent and child values using jpa by passing parent and child values in JSON format

<code>

//restful controller
//sending in the json format and placed the jackson jars in classpath
/*
{
"parentname": "1313131",
"parentcreate_date": "2013-07-11",
"child": [
{
"name": "1.mov",
"create_date": "2013-07-11"
},
{
"name": "2.mov",
"create_date": "2013-07-11"
}
]
}
*/
@RequestMapping(value = "/saveparent", method = RequestMethod.POST)
public ResponseEntity<ErrorMessage> saveParent(@RequestBody Parent parent) {
service.saveParent(parent);
}


@Entity
public class Parent {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;

private String parentname;
private String parentcreate_date;

public List<Child> getChild() {
return child;
}
public void setChild(List<Child> child) {
this.child = child;
}

@OneToMany(cascade = CascadeType.PERSIST,fetch=FetchType.LAZY, mappedBy = "parent")
public List<Child> child;


public void addChild(Child children){
if (this.children == null) {
this.children = new ArrayList<Child>();
}
this.children.add(children);
children.setParent(this);
}


}

@Entity
public class Child {

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;

private String name;
private String create_date;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id",nullable = false, updatable = false, insertable = true)
private Parent parent;

public Parent getParent() {
return parent;
}

public void setParent(Parent parent) {
this.parent = parent;
}





</code>

Viewing all articles
Browse latest Browse all 297

Trending Articles