Si bien me guarda la relacion
antes de guardar va hacia la base y hacer sobre la tabla region pero recorriendo sobre region, y eso es lo que no intiendo. no deberia hacer por la pk completa?
Hibernate: insert into MessageMIT (functionalGroup, priority, service, netElemen
t, product, symptom, place, cause, messageId) values (?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate:
Código problema:
Hibernate: update Message set eventId=?, speech=?, [date]=?, start=?, finish=?,Ver original
select messages0_.region as region0_, messages0_.message as message0_ from MessagesRegions messages0_ where messages0_.region=?
estimatedTime=?, [user]=?, messageStatus=?, messageScope=?, category=?, channels
=?, incidence=?, incidenceOther=? where id=?
Hibernate: insert into MessagesRegions (region, message) values (?, ?)
tengo el siguiente codigo
Código:
/** * hibernate.set * table="MessagesRegions" * inverse="true" * cascade="save-update" * hibernate.collection-key * column="message" * unique="true" * not-null="true" * * hibernate.collection-many-to-many * column="region" * class="ar.com.tma.eb.olm.server.entity.message.MessageRegion" * readonly="true" * hibernate.collection-cache * usage="nonstrict-read-write" */ public Set getRegions() { return regions; } public void setRegions(Set value) { regions = value; } public void addRegion(MessageRegion region) { if (region==null) { throw new IllegalArgumentException("null MessageRegion"); } region.getMessages().add(this); getRegions().add(region); }
Código:
public MessageRegion() { } /** * hibernate.set * table="MessagesRegions" * lazy="true" * readonly="true" * hibernate.collection-key * column="region" * hibernate.collection-many-to-many * column="message" * class="ar.com.tma.eb.olm.server.entity.message.MessageMIT" */ public Set getMessages() { return messages; } public void setMessages(Set value) { messages = value; }
Código:
Muchas gracias por alguna ayuda Session session = HFactory.currentSession(); MessageMIT message = new MessageMIT(); message.setDate(new Date()); message.setUser(user); message.setCategory(category); message.setFunctionalGroup(functionalGroup); message.setMessageStatus(status); message.setChannelsAsSet(channels); message.setPriority(priority); message.setNetElement(netElement); message.setProduct(product); message.setService(service); message.setSymptom(symptom); message.setPlace(place); message.setStart(start); message.setFinish(finish); message.setEstimatedTime(estimatedTime); message.setCause(cause); message.setIncidence(incidence); message.setSpeech(speech); message.setIncidenceOther(incidenceOther); message.setMessageScope(scopes); // create message session.save(message); session.flush(); logger.debug("created message "+message.getId()); // add regions for (Iterator it = regions.iterator(); it.hasNext();) { MessageRegion region = (MessageRegion) it.next(); logger.debug("adding MessageRegion "+region.getId()+" to Message "+message.getId()); message.addRegion(region); } // add voice nets for (Iterator it = voiceNets.iterator(); it.hasNext();) { MessageVoiceNet voiceNet = (MessageVoiceNet) it.next(); logger.debug("adding MessageVoiceNet "+voiceNet.getId()+" to Message "+message.getId()); message.addVoiceNet(voiceNet); } // add data nets for (Iterator it = dataNets.iterator(); it.hasNext();) { MessageDataNet dataNet = (MessageDataNet) it.next(); logger.debug("adding MessageDataNet "+dataNet.getId()+" to Message "+message.getId()); message.addDataNet(dataNet); } // add incidences for (Iterator it = incidences.iterator(); it.hasNext();) { MessageIncidence messageIncidence = (MessageIncidence) it.next(); logger.debug("adding MessageIncidence "+messageIncidence.getId()+" to Message "+message.getId()); message.addIncidence(messageIncidence); } // setup eventId if (eventId==null) { message.setEventId(message.getId()); } else { message.setEventId(eventId); } // update message session.update(message); session.flush(); logger.debug("created/updated message MIT id:"+message.getId()+" eventId:"+message.getEventId()); displayEventCreation(message); return (MessageMIT) message; } catch (HibernateException e) { logger.error("error creating event MIT"); e.printStackTrace(); throw new MessageException(); }