Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA - User and Addresses Entity

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

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

@OneToMany(cascade=CascadeType.ALL,mappedBy="addressOwner")
@PrivateOwned
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 ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic