-->
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.  [ 1 post ] 
Author Message
 Post subject: many name properties to one Table?
PostPosted: Fri Apr 17, 2015 4:28 am 
Newbie

Joined: Fri Apr 17, 2015 4:08 am
Posts: 1
I have a problem how to solve getting data using JPA + Hibernate ...

I have a POJO class 2

Code:
@Entity
public class Person{

   @Id
   private Integer id;
   
   @OneToMany(targetEntity=FirstName.class, fetch = FetchType.EAGER, orphanRemoval=true)
   @Cascade( {CascadeType.ALL} )
   @JoinColumn(name = "id_person")
   private Collection<FirstName> name = new ArrayList<>();

   @OneToMany(targetEntity=SecondName.class, fetch = FetchType.EAGER, orphanRemoval=true)
   @Cascade( {CascadeType.ALL} )
   @JoinColumn(name = "id_person")
   private Collection<SecondName> secondName = new ArrayList<>();
   }

@MappedSuperclass
public abstract class Name {
@Id
   @GeneratedValue(strategy=GenerationType.TABLE, generator="imie_seq")
   @SequenceGenerator(name="imie_seq", sequenceName="imie_seq", allocationSize=1)
   protected Integer id;
   
   protected TypeNameEnum nameType;
   
   protected String name;
}

@Entity
@Table(name="Name")
public class FirstName extends Name{

   public FirstName(){
      nameType = TypeNameEnum.name;
   }
}

@Entity
@Table(name="Name")
public class SecondName extends Name{
   
   public SecondName(){
      nameType = TypeNameEnum.secondaryName;
   }
}

public enum TypeNameEnum {
   name,
   secondaryName
}




I can write data to table Imie without problems. But when reading data from database...
Collection "name" from Person POJO got all records from table Name, but i need only data where enumType == TypeNameEnum.name


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.