English 中文(简体)
HibernateProxy.to 2. 追 la性初步化例外
原标题:HibernateProxy.toString lazy initialization exception

I m getting a weird error while I m debugging my POC. I have 2 entities:

@Getter
@Setter
@Entity
@Table(name = "APPLICANT")
public class Applicant implements Serializable {


    private static final long serialVersionUID = 6060170457948717553L;

    @Id
    @Column(name = "applicant_id", insertable = false, nullable = false)
    private Long applicantId;

    @Column(name = "application_id", unique = true)
    private String applicationId;

    @OneToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "application_id", referencedColumnName = "application_id", insertable = 
    false, updatable = false)
    private ApplicationEntity applicationEntity;

@Getter
@Setter
@Entity
@Table(name = "APPLICATION")
public class ApplicationEntity implements Serializable{

    private static final long serialVersionUID = 7300036359295729197L;

    @Id
    @Column(name = "APPLICATION_ID")
    private String id;

    @OneToOne(mappedBy = "applicationEntity", fetch = FetchType.LAZY)
    private Applicant applicant;

These classes has the repositories interfaces extending from CrudRepository, and in the Applicant repository I have a custom method to get the entity with the applicationId: Applicant findByApplicationId(String applicationId); But, when I m debugging, I see the following message in the intellij debuguer on the applicationEntity attribute:

Method threw org.hibernate. LazyInitializationException exception. Cannot evaluation org.example.postgres.jpa.model.ApplicationEntity$HibernateProxy$qa4PKx8V.toString(

数值qa4PKx8V 每次我进行新的测试时都会发生变化。

我在<代码>@中尝试了许多组合。 Join annotation, I ve/2008/2 the lombook note, I ve used the @ Transactional annotation both, but ishas the same wrong.

A key point to note, is that I can get the data from the table with any error, I just see this message in the debugger, so my question is, this is a thing of intellij or something like that? Or I need to fix this with configuration or changing something in my code?

Thanks.

问题回答

我假设您有自动生成的<代码>至String( 实施?

In general, you should avoid referencing lazily-loaded properties in toString(), equals(), hashCode() etc. Failing to do so will result in LazyInitializationException surprises like the one you re facing, triggered by the aforementioned methods whenever they try to access lazy properties outside of an active transaction context.

(这的确是一回事,因为尽管提单很可能被交易所包围,但英特尔利j监察员在没有任何交易活跃的情况下以单独的线评价这一表述。 而且,只有在<条码>@XxxTo One(optional = 虚假) 的情况下才会发生。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签