小编C. *_*ith的帖子

无法延迟初始化角色集合:myapp.myapp.models.Contact.messages,无法初始化代理 - 无会话

我遇到 org.hibernate.LazyInitializationException:无法延迟初始化角色集合:myapp.myapp.models.Contact.messages,无法初始化代理 - 无会话。我研究过这些类似的问题Hibernate: LazyInitializationException: failed to lazily初始化角色集合。无法初始化代理 - 没有会话以及如何解决 \xe2\x80\x9cfailed to lazily初始化角色\xe2\x80\x9d Hibernate 异常的集合,但它们都没有帮助我的情况。我将 spring 自动配置我的数据源到了没有这个问题的地方,但我添加了另一个数据源连接,然后为每个数据源创建了一个配置文件,现在一切正常,就像以前一样,但我不断收到此消息抛出错误。我不知道该怎么办。任何帮助表示赞赏。

\n\n

在添加其他数据库之前,我的属性文件中的数据库信息看起来像这样

\n\n
##############DBs##################\nspring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect\nspring.jpa.hibernate.ddl-auto=update\nspring.jpa.database=default\n\n#Myapp DB\nspring.datasource.driverClassName=com.mysql.jdbc.Driver\nspring.datasource.url=jdbc:mysql://localhost:3306/myapp?        verifyServerCertificate=false&useSSL=false&requireSSL=false\nspring.datasource.username=myusername\nspring.datasource.password=mypassword\n
Run Code Online (Sandbox Code Playgroud)\n\n

一切顺利。

\n\n

现在一切都是这样设置的。

\n\n

属性文件

\n\n
##############DBs##################\nspring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect\nspring.jpa.hibernate.ddl-auto=update\nspring.jpa.database=default\n\n#Myapp DB\nspring.datasource.driverClassName=com.mysql.jdbc.Driver\nspring.datasource.url=jdbc:mysql://localhost:3306/myapp?        verifyServerCertificate=false&useSSL=false&requireSSL=false\nspring.datasource.username=myusername\nspring.datasource.password=mypassword\n\n#Other DB\nspring.seconddatasource.driverClassName = com.mysql.jdbc.Driver\nspring.seconddatasource.url = jdbc:mysql://localhost:3306/other\nspring.seconddatasource.username=myusername\nspring.seconddatasource.password=mypassword\n###################################\n
Run Code Online (Sandbox Code Playgroud)\n\n

联系单位:

\n\n
@Entity\n@Table(name = "contact")\npublic class Contact {\n\n    @Id\n    @GeneratedValue(strategy = GenerationType.IDENTITY)\n    private long id;\n\n    @OneToMany(fetch = FetchType.LAZY, mappedBy = "contact")\n    private List<Messages> messages;\n\n    public long getId() {\n        return this.id;\n    }\n\n    public void setId(long id) {\n        this.id …
Run Code Online (Sandbox Code Playgroud)

hibernate jpa spring-data-jpa spring-boot

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

标签 统计

hibernate ×1

jpa ×1

spring-boot ×1

spring-data-jpa ×1