SORU
2 Aralık 2010, PERŞEMBE


Hazırda Bekletme aynı anda birden fazla torba getir

Hazırda SessionFactory oluşturulurken: bu özel durum atar

org.Hazırda Beklet.loader.MultipleBagFetchException: aynı anda birden fazla çanta getirilemiyor

Bu test benim davam:

Parent.java

@Entity
public Parent {

 @Id
 @GeneratedValue(strategy=GenerationType.IDENTITY)
 private Long id;

 @OneToMany(mappedBy="parent", fetch=FetchType.EAGER)
 // @IndexColumn(name="INDEX_COL") if I had this the problem solve but I retrieve more children than I have, one child is null.
 private List<Child> children;

}

Child.java

@Entity
public Child {

 @Id
 @GeneratedValue(strategy=GenerationType.IDENTITY)
 private Long id;

 @ManyToOne
 private Parent parent;

}

Nasıl bu sorun hakkında? Ne yapabilirim?


EDİT

TAMAM, o zaman sorun başka bir "üst" varlık ailemin içinde, benim gerçek davranış bu: .

Parent.java

@Entity
public Parent {

 @Id
 @GeneratedValue(strategy=GenerationType.IDENTITY)
 private Long id;

 @ManyToOne
 private AntoherParent anotherParent;

 @OneToMany(mappedBy="parent", fetch=FetchType.EAGER)
 private List<Child> children;

}

AnotherParent.java

@Entity
public AntoherParent {

 @Id
 @GeneratedValue(strategy=GenerationType.IDENTITY)
 private Long id;

 @OneToMany(mappedBy="parent", fetch=FetchType.EAGER)
 private List<AnotherChild> anotherChildren;

}

Hazırda Beklet FetchType.EAGER, ama bu bir hata gibi görünüyor ile iki koleksiyon gibi değil, sıra dışı şeyler yapıyorum

Çıkarma FetchType.EAGER Parent AnotherParent problemi çözer, ama ihtiyacım var, bu yüzden gerçek bir çözüm için kullanın. @LazyCollection(LazyCollectionOption.FALSE) yerine FetchType (teşekkürler Bozho çözüm).

CEVAP
2 Aralık 2010, PERŞEMBE


Hazırda daha yeni bir sürümü (JPA 2.0 destekleyen) bu ele gerektiğini düşünüyorum. Ama aksi takdirde etrafında toplama alanları ile notlar çalışabilirsiniz:

@LazyCollection(LazyCollectionOption.FALSE)

@*ToMany açıklama: fetchType öznitelik kaldırmayı unutmayın.

Ama çoğu durumda Set<Child> gerçekten ihtiyacınız sürece List<Child>, çok daha uygun olduğunu unutmayın List - Set

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Day9TV

    Day9TV

    22 NİSAN 2010
  • Shylo Sharity

    Shylo Sharit

    27 EKİM 2011
  • TechSmartt

    TechSmartt

    29 Aralık 2010