JSONB序列化抛出org.hibernate.SessionException

问题描述 投票:0回答:1

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

Class 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;
}

并且我收到以下错误:

原因:org.hibernate.SessionException:会话已关闭。仅当代理[de.unibremen.sfb.model.Standort#-486533119]与打开的会话相关联时,才能访问只读/可修改的设置。在[email protected]//org.hibernate.proxy.AbstractLazyInitializer.errorIfReadOnlySettingNotAvailable(AbstractLazyInitializer.java:348)在[email protected]//org.hibernate.proxy.AbstractLazyInitializer.setReadOnly(AbstractLazyInitializer.java:362)在[email protected]//org.hibernate.proxy.AbstractLazyInitializer.setSession(AbstractLazyInitializer.java:136)在[email protected]//org.hibernate.proxy.AbstractLazyInitializer。(AbstractLazyInitializer.java:77)在[email protected]//org.hibernate.proxy.pojo.BasicLazyInitializer。(BasicLazyInitializer.java:43)在[email protected]//org.hibernate.proxy.pojo.bytebuddy.ByteBuddyInterceptor。(ByteBuddyInterceptor.java:37)在[email protected]//org.hibernate.proxy.pojo.bytebuddy.ByteBuddyProxyFactory.getProxy(ByteBuddyProxyFactory.java:77)在[email protected]//org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:713)在[email protected]//org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:4872)在[email protected]//org.hibernate.event.internal.DefaultLoadEventListener.createProxy(DefaultLoadEventListener.java:445)在[email protected]//org.hibernate.event.internal.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:436)在[email protected]//org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:344)在[email protected]//org.hibernate.event.internal.DefaultLoadEventListener.doOnLoad(DefaultLoadEventListener.java:127)在[email protected]//org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:93)在[email protected]//org.hibernate.internal.SessionImpl.fireLoadNoChecks(SessionImpl.java:1288)在[email protected]//org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1160)在[email protected]//org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:682)在[email protected]//org.hibernate.type.EntityType.resolve(EntityType.java:464)在[email protected]//org.hibernate.type.ManyToOneType.resolve(ManyToOneType.java:239)在[email protected]//org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:205)在[email protected]//org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:160)在[email protected]//org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.performTwoPhaseLoad(AbstractRowReader.java:252)在[email protected]//org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.finishUp(AbstractRowReader.java:215)在[email protected]//org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:133)在[email protected]//org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:107)在[email protected]//org.hibernate.loader.collection.plan.AbstractLoadPlanBasedCollectionInitializer.initialize(AbstractLoadPlanBasedCollectionInitializer.java:87)在[email protected]//org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:692)在[email protected]//org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:75)在[email protected]//org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:2277)在[email protected]//org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:585)在[email protected]//org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:263)在[email protected]//org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:581)在[email protected]//org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:148)在[email protected]//org.hibernate.collection.internal.PersistentBag.iterator(PersistentBag.java:366)在org.eclipse.yasson // org.eclipse.yasson.internal.serializer.CollectionSerializer.serializeInternal(CollectionSerializer.java:38)在org.eclipse.yasson // org.eclipse.yasson.internal.serializer.CollectionSerializer.serializeInternal(CollectionSerializer.java:27)在org.eclipse.yasson // org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serialize(AbstractContainerSerializer.java:64)在org.eclipse.yasson // org.eclipse.yasson.internal.serializer.AbstractContainerSerializer.serializerCaptor(AbstractContainerSerializer.java:96)在org.eclipse.yasson // org.eclipse.yasson.internal.serializer.ObjectSerializer.marshallProperty(ObjectSerializer.java:110)在org.eclipse.yasson // org.eclipse.yasson.internal.serializer.ObjectSerializer.serializeInternal(ObjectSerializer.java:65)... 138更多

java hibernate exception wildfly h2
1个回答
0
投票

确定,所有包含@ * ToOne关系的标签被无意设置为fetch = FetchType.LAZY,这导致了异常

© www.soinside.com 2019 - 2024. All rights reserved.