0

我有两个具有 OneToMany 关系的实体“contact”和“client”,我想添加一个具有 ManyToOne 属性的联系人,“client”将从 selectOneMenu 中恢复。添加没有完成的问题,它没有给我任何错误。

实体客户端.java

 @Entity

public class Client implements Serializable {
@Id
     @GeneratedValue(strategy = GenerationType.AUTO)

    private int client_id;
    private String client_n;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "client", orphanRemoval=true)

    private List<Contact> contacts;

    @ManyToMany(mappedBy="clients")
    private List<Profil> profils;
    public void addContact(Contact contact) {
        this.contacts.add(contact);
        if (contact.getClient() != this) {
            contact.setClient(this);
        }
    }

服务.java

   public void setContactClient(int contactId, int clientId) {
              dao=new ClientContact();
                dao.beginTransaction();
            Contact contact = findContact(contactId);
            Client client = findClient(clientId);
            client.addContact(contact);
            contact.setClient(client);
            dao.updateT(client);
            dao.updateY(contact);
            dao.closeTransaction();
          }

ManagedBean.java

    @SessionScoped
public class ClientMB extends AbstractMB implements Serializable {
private Client client;
private List<Client> clients;
private ClientService clientService=new ClientService();
private int refCont;
private testService testService=new testService();
 public void addContact(){
System.out.println("début ajout");
testService.setContactClient(refCont,client.getClient_id());
System.out.println("client MB: "+client.getClient_n()+" la liste de ses contacts: "+client.getContacts());
 }

我不知道发生了什么?

4

0 回答 0