openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simone Gianni <>
Subject Re: Self referencing Entity causes id already assigned value on entity save
Date Sat, 31 Jan 2009 00:29:36 GMT
Hi mxc,
could you post the exception stacktrace and the code snippet causing the 
error? the one where you add the entity and the parent and persist them.


mxc wrote:
> Hi all,
> I have a simple node entity pretty much as follows
> -------------------------------------------------
> 	@Id
> 	@GeneratedValue
> 	private Integer id;
> 	private String name;
> 	@ManyToOne(fetch=FetchType.LAZY)
> 	private Node parent;
> 	@OneToMany(mappedBy="parent",fetch=FetchType.LAZY,cascade=CascadeType.ALL)
> 	private ArrayList<Node> children;
> ------------------------------------------------
> When trying to insert into this table with a new entity whose parent is
> already in the table, i.e already has an id I get the errror
> The generated value processing detected an existing value assigned to this
> field:  This existing value was either provided via an
> initializer or by calling the setter method.  You either need to remove the
> @GeneratedValue annotation or modify the code to remove the initializer
> processing.
> I have verified, via step through debug, that the id for the new entity is
> definitely null when persist is called. I have tried flushing the entity
> manager but the error is thrown immedialtly upon persist. The parent field,
> which is the self referencing field, does not have its cascadeType set so I
> cannot see why openjpa is attempting to persist the entity again.
> Any ideas?
> thanks

Simone Gianni            CEO Semeru s.r.l.           Apache Committer

View raw message