Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JPA - User and Addresses Entity  RSS feed

kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

@NamedQueries( {
@NamedQuery(name="AllUsers",query="select user from UserEntity user order by")
public class UserEntity {

private Set<AddressEntity> userAddresses = new HashSet<AddressEntity>();

public UserEntity() {

public Set<AddressesEntity> getUserAddresses() {
return userAddresses;


UserEntity for User table and AddressesEntity for Addresses table. One or more addresses are assocated with particular user. Initially three addresses are associated with User. Deleted the same user, so addresses are automatically deleted. Re-added the same user with only two addresses.
But user.getUserAddresses().size(); returns three instead of two. But addresses table has only two rows.

List users = dao.getusers();

for(UserEntity user: users) {
int size = user.getUserAddresses().size();


Can i add FetchType.EAGER for userAddresses ?
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!