3
Files required: ----------- Product.java Client.java product.hbm.xml hibernate.cfg.xml product_table product_table package com.jlc.pc; import java.util.Date; public class Product { private int pid; private String pname; private double cost; private String mfcompany; private Date mfdate; public Product(){} public Product(String pname,double cost,String mfcompany,Date mfdate) { this.pname=pname; this.cost=cost; this.mfcompany=mfcompany; this.mfdate=mfdate; } Product.java Simple hibernate program ----------- product of company <hibernate-mapping package="com.jlc.pc"> <class name="Product" table="product_table"> <id name="pid" column="pid" type="int"> <generator class="increment"/> </id> <property name="pname" column="pname"/> <property name="cost" column="cost" type="double"/> <property name="mfcompany" column="mfcompany" type="string"/> <property name="mfdate" column="mfdate" type="date"/> </class> Product.java 18

06 Package Cm

  • Upload
    phani

  • View
    212

  • Download
    0

Embed Size (px)

DESCRIPTION

hib prg

Citation preview

Files required: ----------- Product.java Client.java product.hbm.xml hibernate.cfg.xml product_tableproduct_table create databasepapu; use papu; desc product_table; selectfrom table;pac!age com.jlc.pc;import java.util."ate;public class Product#private int pid;private $tring pname;private double cost;private $tring mfcompan%;private "ate mfdate; public Product&'#(public Product&$tring pname)double cost)$tring mfcompan%)"ate mfdate'#this.pname*pname;this.cost*cost;this.mfcompan%*mfcompan%;this.mfdate*mfdate;(++set+get methods(Product.javaSimple hibernate program ----------- product of company,hibernate-mapping pac!age*-com.jlc.pc-.,class name*-Product- table*-product_table-. ,id name*-pid- column*-pid- t%pe*-int-.,generator class*-increment-+. ,+id. ,propert% name*-pname- column*-pname-+. ,propert% name*-cost- column*-cost- t%pe*-double-+. ,propert% name*-mfcompan%- column*-mfcompan%- t%pe*-string-+. ,propert% name*-mfdate- column*-mfdate- t%pe*-date-+.,+class.,+hibernate-mapping.create table product_table&pid int)pname char&/0')cost double)mfcompan% char&/0')mfdate date';Product.java18pac!age com.jlc.product;import java.util.;import com.jlc.pc.;import org.hibernate.cfg.Configuration;import org.hibernate.$essionFactor%;import org.hibernate.$ession;import org.hibernate.1ransaction;public class Client#public static void main&$tring as23'#1ransaction tx*null;tr%#Configuration cfg*ne4 Configuration&';cfg*cfg.configure&';$essionFactor% sf*cfg.build$essionFactor%&';$ession ses*sf.open$ession&';tx*ses.begin1ransaction&';Product product/*ne4 Product&-5atter%-)/0)-$"-)ne4 "ate&'';Product product6*ne4 Product&-7ar!er-)89)-:;C-)ne4 "ate&'';ses.save&product/';ses.save&product6';tx.commit&';ses.close&';(catch& pid> pname > cost > mfcompan% > mfdate >=------=---------=------=-----------=------------=>/ > 5atter% > /0 > $"> 699?-9@-6/ >>6 > 7ar!er> 89 > :;C > 699?-9@-6/ >=------=---------=------=-----------=------------=6 ro4s in set &9.99 sec',hibernate-configuration.,session-factor%.,propert% name*-connection.driver_class-.com.m%sql.jdbc."river,+propert%.,propert% name*-connection.url-.jdbc:m%sql:++localhost+papu,+propert%.,propert% name*-connection.username-.root,+propert%.,propert% name*-connection.pass4ord-.rajiv,+propert%.,propert% name*-dialect-.org.hibernate.dialect.7%$A;"ialect,+propert%.,propert% name*-sho4_sql-.true,+propert%.,mapping resource*-com+jlc+pc+Product.hbm.xml-+.,+session-factor%.,+hibernate-configuration.Client.javaProduct.javaResult-------Output Files required :-------- Product.java Client.java product.hbm.xml hibernate.cfg.xml product_table444.jlcindia.comrajivsh/9/Bgmail.com 1