For example, I have 2 classes. The first
@Entity
@Table(name = "employee")
public class Employee implements Serializable{
@ManyToOne
@JoinColumn(name = "office_address_id")
private Address address;
//setters and getters
}
And the second:
@Entity
@Table(name = "address")
public class Address implements Serializable{
@OneToMany(mappedBy = "address")
private List<Employee> employeeList;
//setters and getters
}
So if I wand read Employee
from database, I read address
field. Address
have employeeList
with LazyInitializingException. But I don't want to know employeeList
. I wanna know only employee.getAddress()
.
I wand to send JSON object Employee
. But at the client-side I have Failed to load resource: the server responded with a status of 500 (Internal Server Error)
by reason of LazyInitializingException .
May I use:
<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>