Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » cascade.PERSIST on Map<Entity, Entity>(Is it possible to cascade EntityManager operations not only on the value Entity, but also on the map key entity ?)
cascade.PERSIST on Map<Entity, Entity> [message #1736028] Fri, 24 June 2016 13:25
Christian Weiers is currently offline Christian WeiersFriend
Messages: 1
Registered: June 2016
Junior Member
I first asked this on SO, but I figured that here might be a better place to ask. The following is more or less copied from there.
The situation is as follows: I have a class with a Map like this:

public class Bar {

    private Long id;

    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "fooMap",
            joinColumns = @JoinColumn(name = "Bar",   referencedColumnName = "ID") , 
            inverseJoinColumns = @JoinColumn(name = "Two_ID", referencedColumnName = "ID") )
    @MapKeyJoinColumn(name = "One_id")
    private Map<FooOne, FooTwo> fooMap;

with key/value-classes like this (FooTwo looks more or less the same):

public class FooOne  {

private Long id;

private String name;

If I populate the map and try to persist it, I get the following exception:

UnitOfWork(117839394)--java.lang.IllegalStateException: During synchronization >a new object was found through a relationship that was not marked cascade >PERSIST: jpa.test.minimalExample.FooOne\@2e4389ed.

because it cascades only to the target of the -toMany association which is the value entity.

Does JPA in general or EclipseLink as implementation offer any form of annotation to cascade actions to the key class of this map? What are my options here ?

I know adding a reference to FooOne in the FooTwo-class works (like this):

  public class FooTwo  {

    private Long id;

    @OneToOne(cascade = cascadeType.ALL)
    private FooOne foo1;

This way, my table FooTwo has an additional column with the fk from FooOne (that I actually don't need, as I already have the map). I would rather have the FooOne table created without the additional relationship.

Previous Topic:Memory issue with PostgreSQL
Goto Forum:

Current Time: Mon Dec 18 09:19:24 GMT 2017

Powered by FUDForum. Page generated in 0.01479 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software