Hi there,
I have 2 tables book and customer, and mapping files, the table book is associated to customer with many-to-one. In the jsp file, which is to insert new book, if I want to insert customer when I input book. I can get all customer info from table and list them in drop down box, when I click save to save the book with customer, it is supposed the bean of customer should be passed with book bean, but in my code, only customer id is passed. How can I fix the problem?
Thanks for your any reply.
Book.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Wed Jul 27 12:01:58 CEST 2005 -->
<hibernate-mapping package="de.laliluna.library">
<class name="Book" table="book" lazy="false">
<id name="id" column="id" type="java.lang.Integer">
<generator class="sequence">
<param name="sequence">book_id_seq</param>
</generator>
</id>
<property name="title" column="title" type="java.lang.String" />
<property name="author" column="author" type="java.lang.String" />
<property name="available" column="available"
type="java.lang.Boolean" />
<many-to-one name="customer" column="customer_fk"
class="Customer" outer-join="false"/>
</class>
</hibernate-mapping>
Customer.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<!-- DO NOT EDIT: This is a generated file that is synchronized -->
<!-- by MyEclipse Hibernate tool integration. -->
<!-- Created Wed Jul 27 12:01:58 CEST 2005 -->
<hibernate-mapping package="de.laliluna.library">
<class name="Customer" table="customer" lazy="false">
<id name="id" column="id" type="java.lang.Integer">
<generator class="sequence">
<param name="sequence">customer_id_seq</param>
</generator>
</id>
<bag name="books" inverse="false">
<key column="customer_fk" />
<one-to-many class="Book" />
</bag>
<property name="name" column="name" type="java.lang.String" />
<property name="lastname" column="lastname"
type="java.lang.String" />
<property name="age" column="age" type="java.lang.Integer" />
</class>
</hibernate-mapping>
bookAdd.jsp
Code:
<%@ page language="java"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<html>
<head>
<title>Add a book</title>
</head>
<body>
<%-- create a html form --%>
<html:form action="bookEdit">
<%-- print out the form data --%>
<table border="1">
<tbody>
<tr>
<td>Author:</td>
<td><html:text property="author" /></td>
</tr>
<tr>
<td>Title:</td>
<td><html:text property="title" /></td>
</tr>
<tr>
<td>Available:</td>
<td><html:checkbox property="available" /></td>
</tr>
<tr>
<td>Customer:</td>
<td>
<html:select property="customer">
<html:options collection="customerlist" property="id" labelProperty="name"/>
</html:select>
</td>
</tr>
</tbody>
</table>
<%-- set the parameter for the dispatch action --%>
<html:hidden property="do" value="saveBook" />
<br>
<%-- submit and back button --%>
<html:button property="back"
onclick="history.back();">
Back
</html:button>
<html:submit>Save</html:submit>
</html:form>
</body>
</html>
N
Code:
eed
help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelpHibernate version: Mapping documents:Code between sessionFactory.openSession() and session.close():Full stack trace of any exception that occurs:Name and version of the database you are using:The generated SQL (show_sql=true):Debug level Hibernate log excerpt:Code:
Code:
Code:
Code: