예를 들어, 나는 2 개의 클래스가 있습니다. 첫 번째최대 절전 모드 LazyInitializingException
@Entity
@Table(name = "employee")
public class Employee implements Serializable{
@ManyToOne
@JoinColumn(name = "office_address_id")
private Address address;
//setters and getters
}
그리고 두 번째 : 나는 데이터베이스에서 Employee
읽기, 막대 그렇다면
@Entity
@Table(name = "address")
public class Address implements Serializable{
@OneToMany(mappedBy = "address")
private List<Employee> employeeList;
//setters and getters
}
, 나는 address
필드를 참조하십시오. Address
에는 LazyInitializingException이있는 employeeList
이 있습니다. 그러나 알고 싶지 않다. employeeList
. 나는 employee.getAddress()
만 알고 싶다. JSON 객체 Employee
을 보내야합니다. 하지만 클라이언트 측에서는 LazyInitializingException을 이유로 Failed to load resource: the server responded with a status of 500 (Internal Server Error)
이 있습니다.
내가 사용할 수 있습니다 :
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="persistenceUnitName" value="myPersistenceUnit"/>
<property name="packagesToScan" value="com.itechart.model"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="databasePlatform" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="showSql" value="false"/>
<property name="generateDdl" value="true"/>
</bean>
</property>
<!-- USE--!>
<property name="jpaProperties">
<props>
<prop key="hibernate.enable_lazy_load_no_trans">true</prop>
</props>
</property>
<!-- END USE--!>
<property name="persistenceProvider">
<bean class="org.hibernate.jpa.HibernatePersistenceProvider"></bean>
</property>
</bean>
모두 같은 이름을 아래처럼 열망에 fetchType을 변경하고 같은 테이블에 매핑 할 수 있습니다를 호출하여 작업을 수행 할 수 있습니다. 그 맞습니까? –
@sam_eera! 오, 미안해! 나는 정확하다. – TestUser
"Address have employeeList with LazyInitializingException"이란 무엇을 의미 하는가? 주소의 employeeList가 지연 초기화되었다는 것을 의미 했습니까? –