|
I've got a detached entity graph which has been unmarshalled with JAXB (Eclipse MOXy). Then I'm using the JPA entity manager to merge this object graph to the session and which is persisted to an Oracle 11g database. The object graph contains existent IDs to manage cross relationships during the umarshall exercise. The JPA entity ID are annotated with an auto generation strategy (which uses by default an Oracle sequence). Each entity have a bi-direction relation as parent/child.
The issue rely with the unidirectional many to many relation from "route" to "street". I'm getting an exception org.hibernate.ejb.Ejb3Configuration$Ejb3EntityNotFoundDelegate.handleEntityNotFound on the "street" parent (city). It works fine if I'm using a single level; a many to many against "route" and "city". Hibernate has handled the "route" child list (from "application") before the "city" child list. I think if the order of the objects was reverse then it should work...
As a workaround I've manually set the ID to null of the "city" objects before applying the merge.
— City — @OneToMany(targetEntity = StreetImpl.class, mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.LAZY) @XmlElement(type = StreetImpl.class, name = "street") private List<Street> streets = new ArrayList<>();
— Street — @ManyToOne(targetEntity = CityImpl.class, optional = false, fetch = FetchType.LAZY) @JoinColumn(name = "CITY_REF", nullable = false, updatable = false, insertable = true) @XmlInverseReference(mappedBy = "streets") @XmlElement(type = CityImpl.class) private City parent;
— Route — @ManyToMany(fetch = FetchType.LAZY, targetEntity = StreetImpl.class, cascade = CascadeType.ALL) @JoinTable(name = "ROUTE_STREET", joinColumns = { @JoinColumn(name = "ROUTE_REF", nullable = false, updatable = false) }
, inverseJoinColumns = { @JoinColumn(name = "STREET_REF", nullable = false, updatable = false) }
) @XmlIDREF @XmlElement(type = StreetImpl.class, name = "street") private List<Street> streets = new ArrayList<>();
|