-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How get List inside list in hibernate
PostPosted: Mon Aug 29, 2016 6:09 am 
Newbie

Joined: Wed Jun 15, 2016 2:38 am
Posts: 4
I have 2 tables email_address and group_email

email_address
id
name
email
is_group

group_email
id
group_id (one to many relationship with id filed email_address table)
email_addr_id (one to many relationship with id filed of email_address table )

I want to get list of email_addresses and if it is group then also list of group email addresses. How should I configure entity?

@Entity
@Table(name = "email_address")
public class EmailAddressDom {

@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "email_address_id_seq")
@SequenceGenerator(name = "email_address_id_seq", sequenceName = "email_address_id_seq")
private int id;

@Column(name = "name")
private String name;

@Column(name = "email")
private String email;

@Column(name = "is_group")
private boolean isGroup;

// which annotation should be there
private List<EmailAddressDom> groupEmails;


Top
 Profile  
 
 Post subject: Re: How get List inside list in hibernate
PostPosted: Fri Sep 02, 2016 12:09 pm 
Newbie

Joined: Mon Jul 02, 2007 1:04 pm
Posts: 3
Could you describe the design goal? It seems very strange to have a is_group column on your email_address table since it seems to represent an email address for a person. The group_email table is where you seem to want to define your groups? The typical design for such a thing, from a purely relational perspective, would be that the group_email would be many:many with email_address - one email could belong to multiple groups and one group can contain many emails. These would probably be best modeled as Entities and would use a bi-directional association.

I would recommend you think about the design a bit more and then grab one of the many good books on JPA/Hibernate and read about some of these basic associations.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.