小编zik*_*ack的帖子

org.hibernate.LazyInitializationException:懒得初始化一个角色集合:FQPropretyName,无法初始化代理 - 没有Session

我正在尝试使用SpringBoot,SpringDataJpa以及使用SpringBootTest进行单元测试的ManyToOne双向关联.但是,测试失败,堆栈跟踪如下所示.但是我无法找到原因.任何指针都会有所帮助

Spring Boot JUnit Test下面的ManyToOne双向关联失败.

    @Test
    public void testFindByRegionIdEquals() {
        Region region = regionService.findByRegionIdEquals(1L);
        Region expectedRegion = new Region(1L, "Europe");
        assertThat(region).isNotNull().isEqualTo(expectedRegion);
        assertThat(region.getCountries()).isNotEmpty().doesNotContainNull().size().isEqualTo(8);
    }
Run Code Online (Sandbox Code Playgroud)

异常StackTrace

    org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: zikzakjack.domain.Region.countries, 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.PersistentSet.isEmpty(PersistentSet.java:149)
    at org.assertj.core.util.IterableUtil.isNullOrEmpty(IterableUtil.java:35)
    at org.assertj.core.internal.Iterables.assertNotEmpty(Iterables.java:152)
    at org.assertj.core.api.AbstractIterableAssert.isNotEmpty(AbstractIterableAssert.java:145)
    at zikzakjack.service.RegionServiceTests.testFindByRegionIdEquals(RegionServiceTests.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Run Code Online (Sandbox Code Playgroud)

拥有实体ManyToOne

@Data
@Entity
@Table(name = "COUNTRIES")
public class Country implements Serializable, Comparable<Country> {

    private static final long serialVersionUID = 1L; …
Run Code Online (Sandbox Code Playgroud)

spring-data-jpa spring-boot spring-boot-test

10
推荐指数
1
解决办法
1万
查看次数

如何使用spring boot jms听主题

我正在尝试使用以下代码段听取主题.但是它默认监听队列.在这种情况下没有xml配置.我完全依赖注释.此外,我完全依赖Spring引导提供的AutoConfiguration.我不知道如何将目标类型设置为主题,在JmsListener中.Spring JMS大师请帮忙.

    @Component
    public class MyTopicListener {

        @JmsListener(destination = "${trans.alert.topic}")
        public void receiveMessage(TransactionAlert alert) {
            logger.info("AlertSubscriberEmail :: Sending Email => <" + alert + ">");
        }
    }
Run Code Online (Sandbox Code Playgroud)

spring spring-jms spring-boot

5
推荐指数
3
解决办法
1万
查看次数

类 org.apache.ignite.IgniteException:无法执行该操作,因为集群处于非活动状态

在摆弄了基本集群之后,我通过在新集群中添加以下配置,尝试了 Ignite 中的本机持久性的另一个示例。

    <!-- Enabling Apache Ignite Persistent Store. -->
    <property name="dataStorageConfiguration">
        <bean class="org.apache.ignite.configuration.DataStorageConfiguration">
            <property name="defaultDataRegionConfiguration">
                <bean class="org.apache.ignite.configuration.DataRegionConfiguration">
                    <property name="persistenceEnabled" value="true"/>
                </bean>
            </property>
        </bean>
    </property>
Run Code Online (Sandbox Code Playgroud)

但是,我无法执行创建/插入/更新/删除操作。我面临以下错误:

class org.apache.ignite.IgniteException: Can not perform the operation because the cluster is inactive. Note, that the cluster is considered inactive by default if Ignite Persistent Store is used to let all the nodes join the cluster. To activate the cluster call Ignite.active(true).
    at org.apache.ignite.internal.processors.query.GridQueryProcessor.querySqlFields(GridQueryProcessor.java:2017)
    at org.apache.ignite.internal.processors.query.GridQueryProcessor.querySqlFields(GridQueryProcessor.java:1979)
    at org.apache.ignite.internal.processors.odbc.jdbc.JdbcRequestHandler.executeQuery(JdbcRequestHandler.java:310)
    at org.apache.ignite.internal.processors.odbc.jdbc.JdbcRequestHandler.handle(JdbcRequestHandler.java:169)
    at org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.onMessage(ClientListenerNioListener.java:148)
    at org.apache.ignite.internal.processors.odbc.ClientListenerNioListener.onMessage(ClientListenerNioListener.java:41)
    at …
Run Code Online (Sandbox Code Playgroud)

ignite

1
推荐指数
1
解决办法
3674
查看次数