SHARE
TWEET

Untitled

a guest Sep 21st, 2016 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package generatedcode;
  2. import java.math.BigDecimal;
  3. import java.util.Date;
  4. import java.util.HashSet;
  5. import java.util.Set;
  6.  
  7. public class Emp implements java.io.Serializable
  8. {
  9.  
  10.     private short empno;
  11.     private Emp emp;
  12.     private Dept dept;
  13.     private String ename;
  14.     private String job;
  15.     private Date hiredate;
  16.     private BigDecimal sal;
  17.     private BigDecimal comm;
  18.     private Set emps = new HashSet(0);
  19.  
  20.  
  21.     public Emp() {
  22.     }
  23.  
  24.     public Emp(short empno) {
  25.         this.empno = empno;
  26.     }
  27.  
  28.     public Emp(short empno, Emp emp, Dept dept, String ename, String job,
  29.             Date hiredate, BigDecimal sal, BigDecimal comm, Set emps) {
  30.         this.empno = empno;
  31.         this.emp = emp;
  32.         this.dept = dept;
  33.         this.ename = ename;
  34.         this.job = job;
  35.         this.hiredate = hiredate;
  36.         this.sal = sal;
  37.         this.comm = comm;
  38.         this.emps = emps;
  39.     }
  40.  
  41.     public short getEmpno() {
  42.         return this.empno;
  43.     }
  44.  
  45.     public void setEmpno(short empno) {
  46.         this.empno = empno;
  47.     }
  48.  
  49.     public Emp getEmp() {
  50.         return this.emp;
  51.     }
  52.  
  53.     public void setEmp(Emp emp) {
  54.         this.emp = emp;
  55.     }
  56.  
  57.     public Dept getDept() {
  58.         return this.dept;
  59.     }
  60.  
  61.     public void setDept(Dept dept) {
  62.         this.dept = dept;
  63.     }
  64.  
  65.     public String getEname() {
  66.         return this.ename;
  67.     }
  68.  
  69.     public void setEname(String ename) {
  70.         this.ename = ename;
  71.     }
  72.  
  73.     public String getJob() {
  74.         return this.job;
  75.     }
  76.  
  77.     public void setJob(String job) {
  78.         this.job = job;
  79.     }
  80.  
  81.     public Date getHiredate() {
  82.         return this.hiredate;
  83.     }
  84.  
  85.     public void setHiredate(Date hiredate) {
  86.         this.hiredate = hiredate;
  87.     }
  88.  
  89.     public BigDecimal getSal() {
  90.         return this.sal;
  91.     }
  92.  
  93.     public void setSal(BigDecimal sal) {
  94.         this.sal = sal;
  95.     }
  96.  
  97.     public BigDecimal getComm() {
  98.         return this.comm;
  99.     }
  100.  
  101.     public void setComm(BigDecimal comm) {
  102.         this.comm = comm;
  103.     }
  104.  
  105.     public Set getEmps() {
  106.         return this.emps;
  107.     }
  108.  
  109.     public void setEmps(Set emps) {
  110.         this.emps = emps;
  111.     }
  112.  
  113. }
  114.    
  115. package generatedcode;
  116.  
  117. import java.util.HashSet;
  118. import java.util.Set;
  119.  
  120. public class Dept implements java.io.Serializable {
  121.  
  122.     private byte deptno;
  123.     private String dname;
  124.     private String loc;
  125.     private Set emps = new HashSet(0);
  126.  
  127.     public Dept() {
  128.     }
  129.  
  130.     public Dept(byte deptno) {
  131.         this.deptno = deptno;
  132.     }
  133.  
  134.     public Dept(byte deptno, String dname, String loc, Set emps) {
  135.         this.deptno = deptno;
  136.         this.dname = dname;
  137.         this.loc = loc;
  138.         this.emps = emps;
  139.     }
  140.  
  141.     public byte getDeptno() {
  142.         return this.deptno;
  143.     }
  144.  
  145.     public void setDeptno(byte deptno) {
  146.         this.deptno = deptno;
  147.     }
  148.  
  149.     public String getDname() {
  150.         return this.dname;
  151.     }
  152.  
  153.     public void setDname(String dname) {
  154.         this.dname = dname;
  155.     }
  156.  
  157.     public String getLoc() {
  158.         return this.loc;
  159.     }
  160.  
  161.     public void setLoc(String loc) {
  162.         this.loc = loc;
  163.     }
  164.  
  165.     public Set getEmps() {
  166.         return this.emps;
  167.     }
  168.  
  169.     public void setEmps(Set emps) {
  170.         this.emps = emps;
  171.     }
  172. }
  173.    
  174. <?xml version="1.0" encoding="UTF-8"?>
  175. <!DOCTYPE hibernate-configuration PUBLIC
  176.     "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  177.     "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
  178. <hibernate-configuration>
  179.     <session-factory>
  180.         <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
  181.         <property name="hibernate.connection.url">jdbc:oracle:thin:@myserver:1521:xe</property>
  182.         <property name="hibernate.connection.username">user</property>
  183.         <property name="hibernate.connection.password">pass</property>
  184.         <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
  185.         <mapping resource="Emp.hbm.xml"/>
  186.         <mapping resource="Dept.hbm.xml"/>
  187.     </session-factory>
  188. </hibernate-configuration>
  189.    
  190. <?xml version="1.0"?>
  191. <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  192. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
  193. <!-- Generated Sep 20, 2016 7:06:48 PM by Hibernate Tools 3.4.0.CR1 -->
  194. <hibernate-mapping>
  195.     <class name="Emp" table="EMP" schema="TTRAK1">
  196.         <id name="empno" type="short">
  197.             <column name="EMPNO" precision="4" scale="0" />
  198.             <generator class="assigned" />
  199.         </id>
  200.         <many-to-one name="emp" class="Emp" fetch="select">
  201.             <column name="MGR" precision="4" scale="0" />
  202.         </many-to-one>
  203.         <many-to-one name="dept" class="Dept" fetch="select">
  204.             <column name="DEPTNO" precision="2" scale="0" />
  205.         </many-to-one>
  206.         <property name="ename" type="string">
  207.             <column name="ENAME" length="10" />
  208.         </property>
  209.         <property name="job" type="string">
  210.             <column name="JOB" length="9" />
  211.         </property>
  212.         <property name="hiredate" type="date">
  213.             <column name="HIREDATE" length="7" />
  214.         </property>
  215.         <property name="sal" type="big_decimal">
  216.             <column name="SAL" precision="7" />
  217.         </property>
  218.         <property name="comm" type="big_decimal">
  219.             <column name="COMM" precision="7" />
  220.         </property>
  221.         <set name="emps" table="EMP" inverse="true" lazy="true" fetch="select">
  222.             <key>
  223.                 <column name="MGR" precision="4" scale="0" />
  224.             </key>
  225.             <one-to-many class="Emp" />
  226.         </set>
  227.     </class>
  228. </hibernate-mapping>
  229.    
  230. <?xml version="1.0"?>
  231. <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  232. "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
  233. <!-- Generated Sep 20, 2016 7:06:48 PM by Hibernate Tools 3.4.0.CR1 -->
  234. <hibernate-mapping>
  235.     <class name="Dept" table="DEPT" schema="TTRAK1">
  236.         <id name="deptno" type="byte">
  237.             <column name="DEPTNO" precision="2" scale="0" />
  238.             <generator class="assigned" />
  239.         </id>
  240.         <property name="dname" type="string">
  241.             <column name="DNAME" length="14" />
  242.         </property>
  243.         <property name="loc" type="string">
  244.             <column name="LOC" length="13" />
  245.         </property>
  246.         <set name="emps" table="EMP" inverse="true" lazy="true" fetch="select">
  247.             <key>
  248.                 <column name="DEPTNO" precision="2" scale="0" />
  249.             </key>
  250.             <one-to-many class="Emp" />
  251.         </set>
  252.     </class>
  253. </hibernate-mapping>
  254.    
  255. package test;
  256.  
  257. import generatedcode.Emp;
  258. import java.util.List;
  259. import org.hibernate.Query;
  260. import org.hibernate.Session;
  261. import org.hibernate.SessionFactory;
  262. import org.hibernate.cfg.*;
  263.  
  264. public class Test
  265. {
  266.     public static void main(String args[])
  267.     {
  268.         Configuration configuration=new Configuration();
  269.         SessionFactory sf=configuration.configure().buildSessionFactory();
  270.  
  271.         Session session=sf.openSession();
  272.         session.beginTransaction();
  273.         Query query=session.createQuery("from Emp");
  274.         List<Emp> empList=query.list();
  275.         for(Emp emp:empList)
  276.         {
  277.             System.out.println("Employee "+emp.getEmpno()+" , "+emp.getEname());
  278.         }
  279.         session.close();
  280.     }
  281. }
  282.    
  283. Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
  284.     at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1491)
  285.     at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)
  286.     at org.hibernate.cfg.Configuration.configure(Configuration.java:1411)
  287.     at test.EmpDAO.main(EmpDAO.java:19)
  288. Caused by: org.dom4j.DocumentException: Connection refused: connect Nested exception: Connection refused: connect
  289.     at org.dom4j.io.SAXReader.read(SAXReader.java:484)
  290.     at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
  291.     ... 3 more
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top