Skip to main content


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:

@Entity
public class Bar {


    @Id
    @GeneratedValue
    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):

@Entity
public class FooOne  {

@Id
@GeneratedValue
private Long id;

@Basic
private String name;
}

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

Quote:
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):

 @Entity
  public class FooTwo  {

    @Id
    @GeneratedValue
    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:EclipseLink Static Weaving Maven Plugin Lifecycle Mapping Problem
Next Topic:QUERY_RESULTS_CACHE vs CACHE_USAGE and QUERY_TYPE
Goto Forum:
  


Current Time: Fri Apr 26 11:14:45 GMT 2024

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

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

Back to the top