-->
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: Probleme bei Many-To-Many Insert
PostPosted: Mon Sep 26, 2005 7:06 am 
Regular
Regular

Joined: Sat Sep 03, 2005 9:07 am
Posts: 87
Location: Graz, AUSTRIA
Hab ein Problem beim Einfügen eines Datensatzes in eine Many-To-Many-Tabelle

Der User hat eine Form mit verschiedenen InputFeldern (zum Hinzufügen eines Kontaktes) zur Verfügung. Dort gibt er einige Daten ein und muss auch noch aus einer SelectBox einen bestimmten "Kontakt-Type" auswählen.
Zwischen der Tabelle Contacts und der Tabelle Contact-typen besteht eine Many-To-Many Beziehung.

Leider bekomm ich beim Insert folgenden FEhler:

Code:
exception

javax.servlet.ServletException: Error calling action method of component with id popupcontact:_id1
   javax.faces.webapp.FacesServlet.service(FacesServlet.java:109)
   org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122)

root cause

javax.faces.FacesException: Error calling action method of component with id popupcontact:_id1
   org.apache.myfaces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:74)
   javax.faces.component.UICommand.broadcast(UICommand.java:106)
   javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:90)
   javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:164)
   org.apache.myfaces.lifecycle.LifecycleImpl.invokeApplication(LifecycleImpl.java:271)
   org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:86)
   javax.faces.webapp.FacesServlet.service(FacesServlet.java:94)
   org.apache.myfaces.component.html.util.ExtensionsFilter.doFilter(ExtensionsFilter.java:122


Hier ist mein InsertStatement:

Code:
public void InsertContact(Long faxId, Long telId, Long geschlechtId, String name, String telefon, String fax, String email, Long primary, Long contacttype) throws Exception {

      Session session = HibernateUtil.currentSession();
      Transaction tx = null;
      try {
         tx = session.beginTransaction();
         
         EtContacts contacts = new EtContacts();
         EtFaxPrefix faxprefix = (EtFaxPrefix) session.get(EtFaxPrefix.class, faxId);
         contacts.setFaxId(faxprefix);
         EtPhonePrefix phoneprefix = (EtPhonePrefix) session.get(EtPhonePrefix.class, telId);
         contacts.setPhoneId(phoneprefix);
         EtGendertype gender = (EtGendertype)session.get(EtGendertype.class, geschlechtId);
         contacts.setgId(gender);
         contacts.setName(name);
         contacts.setPhone(telefon);
         contacts.setFax(fax);
         contacts.setEmail(email);
         contacts.setPrimary(primary);
         
         session.save(contacts);
         
         List list = new ArrayList();
         System.out.println("CONID "+contacts.getConId());
         System.out.println("CONTYPEID " +contacttype);
         list.add(contacts.getConId());
         list.add(contacttype);
                  
         contacts.setEtContactTypeMany(list);
         
         session.save(contacts);
         
         tx.commit();

      }
      catch (Exception ex) {
         if (tx != null)
            tx.rollback();
         msg = bundle.getString("testnachricht");
         context.addMessage(null, new FacesMessage(
               FacesMessage.SEVERITY_WARN, msg, null));
         throw ex;
      }
      finally {
         HibernateUtil.closeSession();
      }

   }


Hibernate braucht bei setEtContactTypeMany eine Collection, also hab ich mir gedacht, ich baue sie so zusammen wie oben, nur leider funzt das nicht.

Irgendeine Ideen, wie ich das machen kann?
Thx!![/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 26, 2005 7:11 am 
Regular
Regular

Joined: Sat Sep 03, 2005 9:07 am
Posts: 87
Location: Graz, AUSTRIA
Damit man sich die DB auch noch vorstellen kann, hier das ER-Modell (Ein Ausschnitt davon)

Image


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