gpt4 book ai didi

java - JSONB 序列化抛出 org.hibernate.SessionException

转载 作者:行者123 更新时间:2023-12-01 18:13:37 24 4
gpt4 key购买 nike

我正在尝试使用 JSONB 导出以下实体:

Prozessschritt 类:

import lombok.*;

import javax.persistence.*;
import java.util.List;

/** Data class for process chain steps */
@Data
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@RequiredArgsConstructor
public class ProzessSchritt {

/** On delete set to invalid */
@NonNull
private boolean isValidData = true;

/** The process step id */
@NonNull
@Id
private int psID;


/** Whether or not the process step has been uploaded */
private boolean uploaded;

/** The transport job to be carried out */
@OneToOne
private TransportAuftrag transportAuftrag;

/** The process step's log */
@NonNull
@OneToMany(fetch = FetchType.LAZY)
private List<ProzessSchrittLog> prozessSchrittLog;

/** The process step template the process step was created from */
@NonNull
@ManyToOne(fetch = FetchType.LAZY)
private ProzessSchrittVorlage prozessSchrittVorlage;

/** Die Zugewiesenen Proben fuer diesen Schritt */
@OneToMany(fetch = FetchType.LAZY)
private List<Probe> zugewieseneProben;

/** The process step state automaton template the automaton was created from (containing all possible states) */
@NonNull
@OneToOne(fetch = FetchType.LAZY)
private ProzessSchrittZustandsAutomat prozessSchrittZustandsAutomat;
}

我的导出方法,包含所有实体的列表在 bean 初始化时调用:

/**
* List of all process steps
*/
private List<ProzessSchritt> psListe;

@PostConstruct
public void init() {
psListe = getAll();
}

/**
* JSON export
*/
public String toJson() {
JsonbConfig config = new JsonbConfig()
.withFormatting(true);

// Create Jsonb with custom configuration
Jsonb jsonb = JsonbBuilder.create(config);
String result = jsonb.toJson(psListe);
log.info("Export von den Auftraegen\n" + result);
return result;
}

我收到以下错误:

Caused by: org.hibernate.SessionException: Session is closed. The read-only/modifiable setting is only accessible when the proxy [de.unibremen.sfb.model.Standort#-486533119] is associated with an open session. at org.hibernate@5.3.13.Final//org.hibernate.proxy.AbstractLazyInitializer.errorIfReadOnlySettingNotAvailable(AbstractLazyInitializer.java:348) at org.hibernate@5.3.13.Final//org.hibernate.proxy.AbstractLazyInitializer.setReadOnly(AbstractLazyInitializer.java:362) at org.hibernate@5.3.13.Final//org.hibernate.proxy.AbstractLazyInitializer.setSession(AbstractLazyInitializer.java:136) at org.hibernate@5.3.13.Final//org.hibernate.proxy.AbstractLazyInitializer.(AbstractLazyInitializer.java:77) at org.hibernate@5.3.13.Final//org.hibernate.proxy.pojo.BasicLazyInitializer.(BasicLazyInitializer.java:43) at org.hibernate@5.3.13.Final//org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor.(ByteBuddyInterceptor.java:37) at org.hibernate@5.3.13.Final//org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyFactory.getProxy(ByteBuddyProxyFactory.java:77) at org.hibernate@5.3.13.Final//org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:713) at org.hibernate@5.3.13.Final//org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:4872) at org.hibernate@5.3.13.Final//org.hibernate.event.internal.DefaultLoadEventListener.createProxy(DefaultLoadEventListener.java:445) at org.hibernate@5.3.13.Final//org.hibernate.event.internal.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:436) at org.hibernate@5.3.13.Final//org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:344) at org.hibernate@5.3.13.Final//org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:127) at org.hibernate@5.3.13.Final//org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:93) at org.hibernate@5.3.13.Final//org.hibernate.internal.SessionImpl.fireLoadNoChecks(SessionImpl.java:1288) at org.hibernate@5.3.13.Final//org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1160) at org.hibernate@5.3.13.Final//org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:682) at org.hibernate@5.3.13.Final//org.hibernate.type.EntityType.resolve(EntityType.java:464) at org.hibernate@5.3.13.Final//org.hibernate.type.ManyToOneType.resolve(ManyToOneType.java:239) at org.hibernate@5.3.13.Final//org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:205) at org.hibernate@5.3.13.Final//org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:160) at org.hibernate@5.3.13.Final//org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.performTwoPhaseLoad(AbstractRowReader.java:252) at org.hibernate@5.3.13.Final//org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.finishUp(AbstractRowReader.java:215) at org.hibernate@5.3.13.Final//org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:133) at org.hibernate@5.3.13.Final//org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:107) at org.hibernate@5.3.13.Final//org.hibernate.loader.collection.plan.AbstractLoadPlanBasedCollectionInitializer.initialize(AbstractLoadPlanBasedCollectionInitializer.java:87) at org.hibernate@5.3.13.Final//org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:692) at org.hibernate@5.3.13.Final//org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:75) at org.hibernate@5.3.13.Final//org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:2277) at org.hibernate@5.3.13.Final//org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:585) at org.hibernate@5.3.13.Final//org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:263) at org.hibernate@5.3.13.Final//org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:581) at org.hibernate@5.3.13.Final//org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:148) at org.hibernate@5.3.13.Final//org.hibernate.collection.internal.PersistentBag.iterator(PersistentBag.java:366) at org.eclipse.yasson//org.eclipse.yasson.internal.serializer.CollectionSerializer.serializeInternal(CollectionSerializer.java:38) at org.eclipse.yasson//org.eclipse.yasson.internal.serializer.CollectionSerializer.serializeInternal(CollectionSerializer.java:27) at org.eclipse.yasson//org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:64) at org.eclipse.yasson//org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serializerCaptor(AbstractContainerSerializer.java:96) at org.eclipse.yasson//org.eclipse.yasson.internal.serializer.ObjectSerializer.marshallProperty(ObjectSerializer.java:110) at org.eclipse.yasson//org.eclipse.yasson.internal.serializer.ObjectSerializer.serializeInternal(ObjectSerializer.java:65) ... 138 more

最佳答案

好吧,我明白了,所有包含 @*ToOne 关系的标签都无意中设置为 fetch=FetchType.LAZY,这导致了异常

关于java - JSONB 序列化抛出 org.hibernate.SessionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60417103/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com