hello group-ians ,
I have been doing the my project with hibernate3+jboss4.0.2+jdk1.4.
i have two tables namely product[ prod_code and other columns] and product_release.[prod_code,prod_tag and rel_date]
and i have three classes namely productsBean,productsPKBean(productcode and producttag properties) and productsRelBean.
mapping files:products.hbm.xml and product_release.hbm.xml.
I am using composite primary key(prod_code and prod_tag ) for the table product_release.
i did prod_code and prod_tag as composite id from the productsPKBean class mapping in theproduct_release.hbm.xml file. and i did many to one mapping with productBean (prod_code) . and i put insert=false update =false in many-to-one relationship..
I created three class objects(productsBean,productsPKBean andproductsRelBean) and set the responsible parameters..and save three objects into the hibernate session..
i believe that all things are happened right.
but "save " command is not executed. no error or warning is araised.
everything is fine..
i dont know "what is the mistake i did"?
plz make help me.
here is my code:
productsBean::
-----------------
package com.meru.licman.bo.products;
import java.io.Serializable;
import java.util.Hashtable;
import java.util.ArrayList;
import java.util.Date;
public class ProductsBean implements Serializable
{
private String productCode;
private String productName;
private String productDesc;
private Date createdOn;
private String createdBy;
private String sendProdCode;
private String path;
private String mode;
private ArrayList productCodeName;
private ArrayList receiveProductTag;
/* Setter Methods */
public void setProductCode(String productCode)
{
this.productCode=productCode;
}
public void setProductName(String productName)
{
this.productName=productName;
}
public void setProductDesc(String productDesc)
{
this.productDesc=productDesc;
}
public void setCreatedOn(Date createdOn)
{
this.createdOn=createdOn;
}
public void setCreatedBy(String createdBy)
{
this.createdBy=createdBy;
}
public void setProductCodeName(ArrayList productCodeName)
{
this.productCodeName=productCodeName;
}
public void setSendProdCode(String sendProdCode)
{
this.sendProdCode=sendProdCode;
}
public void setReceiveProductTag(ArrayList receiveProductTag)
{
this.receiveProductTag=receiveProductTag;
}
public void setPath(String path)
{
this.path=path;
}
public void setMode(String mode)
{
this.mode=mode;
}
/* Getter Methods */
public String getProductCode()
{
return this.productCode;
}
public String getProductName()
{
return this.productName;
}
public String getProductDesc()
{
return this.productDesc;
}
public Date getCreatedOn()
{
return this.createdOn;
}
public String getCreatedBy()
{
return this.createdBy;
}
public ArrayList getProductCodeName()
{
return this.productCodeName;
}
public String getSendProdCode()
{
return this.sendProdCode;
}
public ArrayList getReceiveProductTag()
{
return this.receiveProductTag;
}
public String getMode()
{
return this.mode;
}
public String getPath()
{
return this.path;
}
}
productspkbean:
-----------------
package com.meru.licman.bo.products;
import java.io.Serializable;
public class ProductsPKBean implements Serializable
{
private String productCode;
private String productTag;
public ProductsPKBean()
{}
/* Setter Methods */
public void setProductCode(String productCode)
{
this.productCode=productCode;
}
public void setProductTag(String productTag)
{
this.productTag=productTag;
}
/* Getter Methods */
public String getProductCode()
{
return this.productCode;
}
public String getProductTag()
{
return this.productTag;
}
}
productsrelBean:
-----------------
package com.meru.licman.bo.products;
import java.io.Serializable;
import java.util.Date;
import com.meru.licman.bo.products.ProductsPKBean;
import com.meru.licman.bo.products.ProductsBean;
public class ProductsRelBean
{
private Date currentDate;
//private String productCode;
//private String productTag;
private ProductsPKBean productsPK=new ProductsPKBean();
private ProductsBean products=new ProductsBean();
/* Setter Methods */
public void setCurrentDate(Date currentDate)
{
this.currentDate=currentDate;
}
public void setProductsPK(ProductsPKBean productsPK)
{
this.productsPK=productsPK;
}
/*public void setProductCode(String productCode)
{
this.productCode=productCode;
}
public void setProductTag(String productTag)
{
this.productTag=productTag;
}*/
public void setProducts(ProductsBean products)
{
this.products=products;
}
/* Getter Methods */
public Date getCurrentDate()
{
return this.currentDate;
}
/*public String getProductCode()
{
return this.productCode;
}
public String getProductTag()
{
return this.productTag;
}*/
public ProductsPKBean getProductsPK()
{
return this.productsPK;
}
public ProductsBean getProducts()
{
return this.products;
}
}
products.hbm.xml:
-----------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.meru.licman.bo.products.ProductsBean" table="product_master">
<id name="productCode" type="java.lang.String" column="prod_code">
<generator class="assigned"/>
</id>
<property name="productName">
<column name="prod_name" />
</property>
<property name="productDesc">
<column name="prod_description"/>
</property>
<property name="createdOn">
<column name="created_on"/>
</property>
<property name="createdBy">
<column name="created_by"/>
</property>
</class>
</hibernate-mapping>
productsRelease.hbm.xml:
---------------------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.meru.licman.bo.products.ProductsRelBean" table="product_release">
<!-- ProductsPKBean is another class the implements Serializable -->
<composite-id name="productsPK"
class="com.meru.licman.bo.products.ProductsPKBean" >
<key-property name="productCode" column="prod_code" />
<key-property name="productTag" column="prod_tag" />
</composite-id>
<!-- Normal properties of a java class -->
<property name="currentDate" column="rel_date" ></property>
<many-to-one name="products" update="false" class="com.meru.licman.bo.products.ProductsBean" not-null="true">
<column name="prod_code" />
</many-to-one>
</class>
</hibernate-mapping>
here is my invoking class:
------------------------------
try
{
Session session =HibernateConnectionFactory.instance().getSession();
log.debug(className+"get the session from HibernateConnectionFactory class"+session);
trans=session.beginTransaction();
log.debug(className+"begin transaction"+trans);
Date date=Calendar.getInstance().getTime();
try
{
ProductsRelBean productsRelBean=new ProductsRelBean();
ProductsBean productsBean=new ProductsBean();
ProductsPKBean productsPK=new ProductsPKBean();
log.debug(className+"AFTER INSTANTIATE PERSISTANCE OBJECT");
productsBean.setProductCode(request.getParameter("productcode"));
productsBean.setProductName(request.getParameter("productname"));
productsBean.setProductDesc(request.getParameter("productdesc"));
productsBean.setCreatedOn(date);
productsBean.setCreatedBy(usersBean.getUserName());
log.debug(className+"AFTER STORING THE PRODUCTSBEAN OBJECT");
productsPK.setProductTag(request.getParameter("producttag"));
productsPK.setProductTag(request.getParameter("productcode"));
log.debug(className+"AFTER STORING THE PRODUCTSPKBEAN OBJECT");
productsRelBean.setCurrentDate(date);
productsRelBean.setProductsPK(productsPK);
productsRelBean.setProducts(productsBean);
log.debug(className+"AFTER STORING THE PRODUCTSRELBEAN OBJECT");
//session.load(ProductsBean.class,productsBean);
//session.load(ProductsRelBean.class,productsPK);
session.save(productsBean);
log.debug(className+"AFTER SAVING THE PRODUCTSBEAN INTO SESSION OBJECT");
session.save(productsPK);
log.debug(className+"AFTER SAVING THE PRODUCTSPKBEAN INTO SESSION OBJECT");
session.save(productsRelBean);
log.debug(className+"AFTER SAVING THE PRODUCTSRELBEAN INTO SESSION OBJECT");
trans.commit();
log.debug(className+"AFTER GIVING COMMIT");
}catch(Exception e)
{
throw e;
}
_________________ Without self-Confidence ,Without Life
Regards,
Vikneswaran.T
|