  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | Hibernate: one-to-many relation. Getting values | Hibernate: one-to-many relation. Getting values 2007-11-07 - By l1nk
Back
Hi. Im developing a web application at work using Struts2, Hibernate and Spring.
I have two classes with a parent/child (PCB - BrgpInfo) relation and i make one JSP page to insert data to populate this 2 classes. The problem is that i can read all the information but i cant insert data to the Set<BrgpInfo>.
[B]Pcb.java[/B] [CODE] import java.io.Serializable; import java.util.Iterator; import java.util.Set;
public class Pcb implements Serializable{
private static final long serialVersionUID = 5925233207935081072L;
/* Primary Key */ private int id; /* Properties */ private String serialNumber; private String origem;
/* Procedure information */ private FailInfo failInfo; //private ClientInfo clientInfo; /* Lista de BrgP info */ private Set<BrgpInfo> brgpInfos;// = new HashSet<BrgpInfo>(); //private List<BrgpInfo> brgpInfos = new ArrayList<BrgpInfo>(); public Pcb() { super(); // TODO Auto-generated constructor stub } public Pcb(int id){ this.id = id; }
public Pcb(int id, String serialNumber, String origem, FailInfo failInfo, Set<BrgpInfo> brgpInfos) { super(); this.id = id; this.serialNumber = serialNumber; this.origem = origem; this.failInfo = failInfo; this.brgpInfos = brgpInfos; }
public Set<BrgpInfo> getBrgpInfos() { return brgpInfos; }
public void setBrgpInfos(Set<BrgpInfo> brgpInfos) { this.brgpInfos = brgpInfos; }
public FailInfo getFailInfo() { return failInfo; }
public void setFailInfo(FailInfo failInfo) { this.failInfo = failInfo; }
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getOrigem() { return origem; }
public void setOrigem(String origem) { this.origem = origem; }
public String getSerialNumber() { return serialNumber; }
public void setSerialNumber(String serialNumber) { this.serialNumber = serialNumber; } } [/CODE]
[B]BrgpInfo.java[/B] [CODE]import java.io.Serializable;
public class BrgpInfo implements Serializable{ private static final long serialVersionUID = -1848147187786536525L; private int id; private String receptDate; private String controlN; private String pcbN;
//private int pcbId; private Pcb pcb;
public BrgpInfo() { super(); // TODO Auto-generated constructor stub }
public BrgpInfo(int id){ this.id = id; } /*Constructor necess??rio para a rela????o one-to-many*/ public BrgpInfo(Pcb pcb){ setPcb(pcb); }
public BrgpInfo(int id, String receptDate, String controlN, String pcbN, Pcb pcb) { super(); this.id = id; this.receptDate = receptDate; this.controlN = controlN; this.pcbN = pcbN; this.pcb = pcb; }
public String getControlN() { return controlN; }
public void setControlN(String controlN) { this.controlN = controlN; }
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public Pcb getPcb() { return pcb; }
public void setPcb(Pcb pcb) { this.pcb = pcb; }
public String getPcbN() { return pcbN; }
public void setPcbN(String pcbN) { this.pcbN = pcbN; }
public String getReceptDate() { return receptDate; }
public void setReceptDate(String receptDate) { this.receptDate = receptDate; }
}[/CODE]
[B]Pcb.hbm.xml[/B] [CODE] <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3 (See http://ing-3.ora-code.com).0.dtd"> <hibernate-mapping> <class name="com.ht.model.Pcb" table="Pcb">
<id name="id" type="integer"> <generator class="native"></generator> </id>
<property name="serialNumber" /> <property name="origem" /> <set name="brgpInfos" table="BrgpInfo" cascade="all-delete-orphan" inverse="true" lazy="false"> <key column="pcb_id" not-null="true"/> <one-to-many class="com.ht.model.BrgpInfo"/> </set> <many-to-one name="failInfo" column="failInfo_id" unique="true" not-null="true" cascade="all" class="com.ht.model.FailInfo" /> </class> </hibernate-mapping> [/CODE]
[B]BrgpInfo.hbm.xml[/B] [CODE] <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3 (See http://ing-3.ora-code.com).0.dtd"> <!-- Generated 3/Set/2007 17:09:40 by Hibernate Tools 3.2.0.b9 --> <hibernate-mapping> <class name="com.ht.model.BrgpInfo" table="BrgpInfo" >
<id name="id" type="integer" column="brgpinfo_id"> <generator class="native"></generator> </id> <property name="receptDate" /> <property name="controlN" />
<property name="pcbN" /> <many-to-one name="pcb" class="com.ht.model.Pcb" column="pcb_id" not-null="true"/>
</class> </hibernate-mapping> [/CODE]
My JSP it's this: [CODE] <s:form method="post" action="done"> <!--PCB --> <h4>Serial Number</h4> <s:textfield name="pcb.serialNumber" cssClass="registration_text"/> <br/> <h4>Origem</h4> <s:textfield name="pcb.origem" cssClass="registration_text"/> <br/>
<!--BRGPINFO DATA --> <h4>Recept Date</h4> <s:textfield name="pcb.brgpInfos.receptDate"/><br/> <h4>Control Number</h4> <s:textfield name="pcb.brgpInfos.controlN"/><br/> <h4>Pcb Number</h4> <s:textfield name="pcb.brgpInfos.pcbN"/><br/> [/CODE]
To read data from the Set i use the <s:iterator> tag and work just fine. What i need to do to insert? -- View this message in context: http://www.nabble.com/Hibernate%3A-one-to-many -relation.-Getting-values-tf4764061.html#a13625307 Sent from the Struts - User mailing list archive at Nabble.com.
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ To unsubscribe, e-mail: user-unsubscribe@(protected) For additional commands, e-mail: user-help@(protected)
|
|
 |