Posts

Showing posts with the label Hibernate

Eager and Lazy Loading In Hibernate and JPA

Image
Suppose if we have two entities and there is a relationship between them. For example, we might have an entity called User and another entity called Order and a User might have many Orders: The User entity might have some basic properties such as id, name, address, etc. as well as a collection property called orders that returns the list of orders for a given User public class User { private Long userId ; private String username ; private String address ; private Set<Order> order = new HashSet<Order>(); public Long getUserId() { return userId ; } public void setUserId(Long userId) { this . userId = userId; } public String getUsername() { return username ; } public void setUsername(String username) { this . username = username; } public Set<Order> getOrder() { return order ; } public void setOrder(Set<Order> order) { this . order