entitymanager 不会保留所有电话以供联系

entitymanager will not persist all phones for contact

我有以下实体。 接触。人。组织。和 Telefoon(Phone 英文)。

一个人和一个组织都是联系人。他们继承自联系人。

一个联系人可以有一个或多个电话号码。所以来自 Telefoon 的列表。

组织也有来自类型人员的联系人。

问题是如果我坚持个人对象和组织对象, 每个对象都有 2 个数字,对于某些对象,数据库中只保留 1 个电话号码?怎么样?

我知道这与我的注释和我的 classes 配置有关。

class联系人

@Entity
@Table(name= "Contact")
@Inheritance(strategy = InheritanceType.JOINED)
@XmlRootElement
public class Contact implements Serializable {
    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    private String naam;
    @Embedded
    private Adres adres;

    public Contact() {}

    @OneToMany(mappedBy="contact", orphanRemoval=true,cascade = CascadeType.ALL)
    @XmlElement
    private List<Telefoon> telefoons=new ArrayList<>();

class 人

@Entity
@Table(name="Persoon")
@Inheritance(strategy= InheritanceType.JOINED)
public class Persoon extends Contact implements Serializable{
    @Convert(converter=LocalDatePersistenceConverter.class)
    private LocalDate geboorteDatum;

    protected Persoon() {}

@OneToMany(mappedBy="contactPersoon",orphanRemoval=true,cascade = CascadeType.ALL)    
      private List<Organisatie> Organisaties;

class组织:

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class Organisatie extends Contact implements Serializable{
    protected Organisatie() {}

    @JoinColumn(name = "persoonid")
    @ManyToOne(cascade=CascadeType.ALL)
    private Persoon contactPersoon;

class 电话(Phone 英文)

@Entity
@Table(name = "Telefoon")
public class Telefoon implements Serializable {
   @Id
   @GeneratedValue(strategy = GenerationType.IDENTITY)
   private long id;


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

   @JoinColumn(name = "contactid")
   @ManyToOne
   private Contact contact;

我以这种方式持久化我的对象:

persoon1.addTelefoon(new Telefoon("Huis","092243851"));
persoon1.addTelefoon(new Telefoon("Mobiel","0478451226"));
persoon2.addTelefoon(new Telefoon("Huis","095547812"));
persoon2.addTelefoon(new Telefoon("Mobiel","0425154578"));
persoon3.addTelefoon(new Telefoon("Huis","097784152"));
persoon3.addTelefoon(new Telefoon("Mobiel","0478221144"));
persoon4.addTelefoon(new Telefoon("Huis","095862314"));
persoon4.addTelefoon(new Telefoon("Mobiel","0423887799"));
persoon5.addTelefoon(new Telefoon("Huis","097841526"));
persoon5.addTelefoon(new Telefoon("Mobiel","0478220033"));
contactpersoon1.addTelefoon(new Telefoon("Huis","092261236"));
contactpersoon1.addTelefoon(new Telefoon("Mobiel","0499150327"));
contactpersoon2.addTelefoon(new Telefoon("Huis","097842615"));
contactpersoon2.addTelefoon(new Telefoon("Mobiel","0499369101"));
contactpersoon3.addTelefoon(new Telefoon("Huis","091142563"));
contactpersoon3.addTelefoon(new Telefoon("Mobiel","0452119987"));
organisatie1.addTelefoon(new Telefoon("Huis","094578956"));
organisatie1.addTelefoon(new Telefoon("Mobiel","0488125200"));
organisatie2.addTelefoon(new Telefoon("Huis","091247653"));
organisatie2.addTelefoon(new Telefoon("Mobiel","0487930287"));
organisatie3.addTelefoon(new Telefoon("Huis","09784561346"));
organisatie3.addTelefoon(new Telefoon("Mobiel","0476112233"));
em.getTransaction().begin();
em.persist(persoon1);
em.persist(persoon2);
em.persist(persoon3);
em.persist(persoon4);
em.persist(persoon5);
em.persist(organisatie1);
em.persist(organisatie2);
em.persist(organisatie3);
em.merge(contactpersoon1);
em.merge(contactpersoon2);
em.merge(contactpersoon3);
em.getTransaction().commit();

但是数据库不会显示所有家庭号码和手机号码! 有些被遗漏了!

有什么想法吗?

谢谢

我找到了答案。 Glassfish 在数据库中保存日期时遇到问题。

class 人的日期 属性 由 class 转换我自己写的。只是为了编辑数据库中日期的标记。

glassfish 似乎无法处理。 我还删除了带有 Organisatie(组织)列表的 oneToMany。

这个:

@Entity
@Table(name="Persoon")
@Inheritance(strategy= InheritanceType.JOINED)
public class Persoon extends Contact implements Serializable{
    @Convert(converter=LocalDatePersistenceConverter.class)
    private LocalDate geboorteDatum;

    protected Persoon() {}

@OneToMany(mappedBy="contactPersoon",orphanRemoval=true,cascade = CascadeType.ALL)    
      private List<Organisatie> Organisaties;

现在是这样的:

@Entity
@XmlRootElement
public class Persoon extends Contact implements Serializable {


    @Temporal(DATE)
    private Date geboorteDatum;

    public Persoon() {
    }
}

现在一切正常! 谢谢