views:

98

answers:

1

I am getting "During synchronization a new object was found through a relationship that was not marked cascade PERSIST" when attempting to persist an object Word() that has a Many-To-Many field mapping to a table Topics. The relations bridge table is Topic_links. What complicates the problem is that I always use the Eclipse Workbench to setup my entities, which makes it hard to find solutions as most people suggest answers using annotations, which the workbench does not use. I have not found a way in the workbench to set the CASCADE option for the relationship to PERSIST. I have added the following entry to the persistence.xml:

<property name="eclipselink.persistence-context.persist-on-commit" value="true"/>

The exception is still being thrown.

+1  A: 

I'm not totally sure of the syntax because it appears that the Eclipse Workbench uses native EclipseLink ORM XML file but with standard JPA XML mappings, you can setup cascading by adding a <cascade> element inside the <many-to-many>, something like this:

<many-to-many name="projects" target-entity="Project">
    <join-table name="PROJ_EMP">
        <join-column name="EMP_ID" />
        <inverse-join-column name="PROJ_ID" />
    </join-table>
    <cascade>
        <cascade-persist/>
    </cascade>
</many-to-many>

But you should really change your habits, Eclipse Workbench is not ideal for JPA development. Quoting James Sutherland in this Workbench to use annotations thread:

The EclipseLink Workbench is the UI for the native (old) EclipseLink ORM XML file, OXM and EIS, is it not meant for JPA development. Eclipse Dali, Oracle JDeveloper or other such JPA tools should be used for this.

Pascal Thivent