-->
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: Two formbacking objects in jsp form
PostPosted: Sat Mar 15, 2008 6:32 am 
Beginner
Beginner

Joined: Sat Dec 01, 2007 4:34 pm
Posts: 20
In my jsp file I want to use a formbacking object. My problem is that the fields in my jsp file are connected to two different tables.

In the code below productId, productName and productAddress are connected to table Product through Product.hbm.xml.
ProductPrice are connected to table UserProduct through UserProduct.hbm.xml

How can have one commandobject for this form?

In the code below I'm using product, but that doesn't work...


product.jsp

Code:
<form:form method="post" commandName="product">
            <table class="inputTable">
              <tr>
                <td><label >Navn:</label></td>
                <td><form:input path="productName"/></td>
              </tr>
              <tr>
                <td><label>Adresse:</label></td>
                <td><form:input path="productAddress"/></td>
              </tr>
              <tr>
                <td><label >Pris:</label></td>
                <td><form:input path="productPrice"/></td>
              </tr>
  </form:form>


Product.hbm.xml
Code:
<hibernate-mapping>
  <class name="db.Product" table="Product">
    <id name="ProductID"  type="long" column="ProductID">
      <generator class="native"/>
    </id>
    <property name="productName"    column="ProductName"    type="string"/>
  </class>
</hibernate-mapping>



UserProduct.hbm.xml

Code:
<hibernate-mapping>
  <class name="db.UserProduct" table="UserProduct">
    <id name="UserProductID"  type="long" column="UserProductID">
      <generator class="native"/>
    </id>
    <property name="Username"   column="Username"/>
    <property name="ProductID"  column="ProductID"/>
    <property name="Price"      column="Price"      type="string"/>
  </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 16, 2008 6:21 am 
Beginner
Beginner

Joined: Fri Jun 25, 2004 11:47 am
Posts: 34
Hi,

In your UserProduct hbm file you will need to change:

Code:
<property name="ProductID"  column="ProductID"/>


by
Code:
<many-to-one name="product" class="db.Product" column="ProductID"/>


Then in your POJO you will have a reference from UserProduct to Product.

Rgds


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.