のコレクションを初期化できませんでした私はコレクションを持つエンティティを持っている、と私は怠け者で、負荷のエンティティをしたいと思いますが、私はエラーを得た:エラー遅延ロード:com.fasterxml.jackson.databind.JsonMappingExceptionは:怠惰な役割
Caused by: com.fasterxml.jackson.databind.JsonMappingException: failed to lazily initialize a collection of role: lu.entities.folders.Folders.requests, could not initialize proxy - no Session (through reference chain: lu.entities.folders.Folders.requests)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:210)
at com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:177)
at com.fasterxml.jackson.databind.ser.std.StdSerializer.wrapAndThrow(StdSerializer.java:190)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:674)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:156)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:129)
at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:851)
at org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider.writeTo(ResteasyJackson2Provider.java:207)
at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.writeTo(AbstractWriterInterceptorContext.java:131)
at org.jboss.resteasy.core.interception.ServerWriterInterceptorContext.writeTo(ServerWriterInterceptorContext.java:60)
at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:120)
at org.jboss.resteasy.security.doseta.DigitalSigningInterceptor.aroundWriteTo(DigitalSigningInterceptor.java:145)
at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:124)
at org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor.aroundWriteTo(GZIPEncodingInterceptor.java:100)
at org.jboss.resteasy.core.interception.AbstractWriterInterceptorContext.proceed(AbstractWriterInterceptorContext.java:124)
at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:98)
at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:466)
... 38 more
Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: lu.pgd.ccpd.entities.folders.Folders.requests, could not initialize proxy - no Session
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:587)
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:204)
at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:148)
at org.hibernate.collection.internal.PersistentBag.size(PersistentBag.java:261)
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:88)
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:24)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:575)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:666)
... 51 more
そして、私のエンティティのように:私のDAOで
@Entity
@Table(name = "FOLDER_FR")
@JsonIdentityInfo(scope=Folders.class, generator = ObjectIdGenerators.PropertyGenerator.class, property="id")
public class Folders implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "FR_ID")
private Long id;
@LazyCollection(LazyCollectionOption.TRUE)
@JsonIgnore
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinTable(name = "M_REQUESTFOLDER_RR", joinColumns = {
@JoinColumn(name = "RR_FOLDER", referencedColumnName = "FR_ID") }, inverseJoinColumns = {
@JoinColumn(name = "RR_REQUEST", referencedColumnName = "RS_ID") })
private List<Requests> requests = new ArrayList<Requests>();
}
:だから
@Override
public Folders retrieveFolder(Long id) throws PersistenceException {
Folders folders = entityManager.find(Folders.class, id);
return folders;
}
私はそれを解決する方法JPAで? 私のメソッドを呼び出すと何が問題になりますretrieveFolder?
ありがとうございました
[OK]を、私はFETCH JOINをしてJPQLクエリを使用している場合、私の要求は、応答のためのいくつかの時間(5秒)を取る..しかし、私は怠惰な負荷を使用する場合、私は良好な性能を持っている..私は追加しようとしました私のメソッドのiterator()はロードされません。 – user1814879
SQLロギングを有効にできますか? org.hibernate.SQLロガーをDEBUGに設定し、getがJOIN FETCHで実行されたクエリをポストします。あなたは外部キーのインデックスを持っていますか? –
私は外部キーを持っていません、関連テーブルFOLDER_REQUEST(idFolder、idRequest) – user1814879