1
@Table(name="A")
public class A implements Serializable {
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Long id;

   @OneToMany(mappedBy = "b", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
   private List<B> bList;

  //getter and setters
}

@Table(name="B")
public class B implements Serializable {
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Long id;

   @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
   private A a;

   @OneToMany(mappedBy = "c", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
   private List<C> cList;

  //getter and setters
}

@Table(name="C")
public class C implements Serializable {
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Long id;

   @ManyToOne(fetch = FetchType.LAZY)
   private B b;

   @OneToMany(mappedBy = "d", cascade = CascadeType.ALL, fetch = FetchType.EAGER)
   private List<D> dList;

  //getter and setters
}

@Table(name="D")
public class D implements Serializable {
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Long id;

   @ManyToOne(fetch = FetchType.LAZY)
   private C c;

  //getter and setters
}

@Table(name="E")
public class E implements Serializable {
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   private Long id;

   @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
   private C c;

  //getter and setters
}

A (双方向 B) ^ | B (双方向 A および C) ^ | C ((双方向 B および D) および (単方向 E)) ^ ^ | | | DE

エンティティ E の 1 年分のデータが必要です (したがって、単方向接続)。

クラスは、双方向または単方向で接続されます。エンティティ A を保存すると、次の例外が発生します。

<openjpa-2.1.2-SNAPSHOT-r422266:1384519 fatal user error> org.apache.openjpa.persistence.InvalidStateException: Encountered unmanaged object "com.xxx.yyy.data.entity.C@18e0a217" in life cycle state unmanaged while cascading persistence via field "com.xxx.yyy.data.entity.E.c" during flush. However, this field does not allow cascade persist. You cannot flush unmanaged objects or graphs that have persistent associations to unmanaged objects. Suggested actions: a) Set the cascade attribute for this field to CascadeType.PERSIST or CascadeType.ALL (JPA annotations) or "persist" or "all" (JPA orm.xml), b) enable cascade-persist globally, c) manually persist the related field value prior to flushing. d) if the reference belongs to another context, allow reference to it by setting StoreContext.setAllowReferenceToSiblingContext(). FailedObject: com.xxx.yyy.data.entity.C@18e0a217
4

0 に答える 0