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.  [ 4 posts ] 
Author Message
 Post subject: Strange Behavior of Hibernate - NOT RESPONDING
PostPosted: Wed Aug 09, 2006 10:45 pm 
Newbie

Joined: Thu Jul 20, 2006 5:00 pm
Posts: 16
I am running Emp-Dept one-to- many example with Eclipse 3.2 and hibernate3.2 When I run the client program t insert the record, hibernate is not responding. It is just printing the following message on the console....

Starting ..
Saving data for Emp..
Hibernate: select emp_.empno, emp_.deptno, emp_.sal as sal0_, emp_.loc as loc0_ from EMP emp_ where emp_.empno=? and emp_.deptno=?
Hibernate: insert into DEPT (deptname, empno, deptno) values (?, ?, ?)


When I am taking out the relationship its working fine, if somethng is wrong with mapping or somewhere else ... why Hibernate is not complaing abt error rather than sitting quit??? And, thread is ALIVE.

Below is code.

Dept.java
---------------------------------------------------------------

code:


package hello;

import java.util.Set;

public class Dept
{
private String deptname;
private DeptKey key;
private Set emp;

public Set getEmp() {
return emp;
}

public void setEmp(Set emp) {
this.emp = emp;
}

public DeptKey getKey() {
return key;
}

public void setKey(DeptKey key) {
this.key = key;
}

public String getDeptname ()
{
return deptname;
}

public void setDeptname (String deptname)
{
this.deptname = deptname;
}
}




DeptKey.java (Composite PK Class)
---------------------------------------------------------------

code:


package hello;

import java.io.Serializable;

public class DeptKey implements Serializable
{

private String empno;
private String deptno;


public String getDeptno ()
{
return deptno;
}
public void setDeptno (String deptno)
{
this.deptno = deptno;
}
public String getEmpno ()
{
return empno;
}
public void setEmpno (String empno)
{
this.empno = empno;
}
public int hashCode ()
{
return this.hashCode();
}

public boolean equals (Object other)
{
if ( (this == other))
return true;
return false;
}
}




Emp.java
---------------------------------------------------------------

code:



package hello;

public class Emp
{
private EmpKey key;
private String sal;
private String loc;


public EmpKey getKey ()
{
return key;
}

public void setKey (EmpKey key)
{
this.key = key;
}
public String getLoc ()
{
return loc;
}

public void setLoc (String loc)
{
this.loc = loc;
}

public String getSal ()
{
return sal;
}

public void setSal (String sal)
{
this.sal = sal;
}

}

EmpKey.java
---------------------------------------------------------------

code:



package hello;

import java.io.Serializable;

public class EmpKey implements Serializable
{

private String empno;
private String deptno;


public String getDeptno ()
{
return deptno;
}

public void setDeptno (String deptno)
{
this.deptno = deptno;
}

public String getEmpno ()
{
return empno;
}

public void setEmpno (String empno)
{
this.empno = empno;
}

public int hashCode ()
{
return this.hashCode();
}

public boolean equals (Object other)
{
if ( (this == other))
return true;
return false;
}
}




dept.hbm.xml
---------------------------------------------------------------

code:


<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="hello">
<class name="Dept" table="DEPT">

<composite-id name="key" class="DeptKey">
<key-property name="empno" type="string"/>
<key-property name="deptno" type="string"/>
</composite-id>

<property name="deptname" type="string"/>


<set name="emp" table="emp" inverse="true" cascade="all" lazy="false">
<key>
<column name="EMPNO" />
<column name="DEPTNO" />
</key>
<one-to-many class="Emp" />
</set>

</class>
</hibernate-mapping>




emp.hbm.xml
---------------------------------------------------------------

code:


<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="hello">
<class name="Emp" table="EMP">

<composite-id name="key" class="EmpKey">
<key-property name="empno" type="string"/>
<key-property name="deptno" type="string"/>
</composite-id>

<property name="sal" type="string"/>
<property name="loc" type="string"/>

</class>
</hibernate-mapping>



Client.java
---------------------------------------------------------------

code:



import java.util.HashSet;
import java.util.Set;

import hello.Dept;
import hello.DeptKey;
import hello.Emp;
import hello.EmpKey;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class Client {


private void insertRecord()
{

SessionFactory sessionFactory = new Configuration().configure ().buildSessionFactory ();
Session session = sessionFactory.openSession ();
Transaction tx = session.beginTransaction();

System.out.println("Starting .. ");
tx.begin();

EmpKey empKey = new EmpKey();
empKey.setDeptno("dept1");
empKey.setEmpno("emp1");

Emp emp = new Emp();
emp.setKey(empKey);
emp.setLoc("California");
emp.setSal("1000");

DeptKey deptKey = new DeptKey();
deptKey.setDeptno("dept1");
deptKey.setEmpno("emp1");

Dept dept = new Dept();
dept.setKey(deptKey);
dept.setDeptname("IT");

Set empSet = new HashSet();
empSet.add(emp);
dept.setEmp(empSet);

System.out.println("Saving data for Emp and Dept..");
session.save(dept);
tx.commit();

System.out.println("Transaction committed ..");


}


public static void main(String args[])
{
new Client().insertRecord();
}

}


-----------------------------------------

SQL> desc emp
Name Null? Type
----------------------------------------- -------- ----------------
EMPNO NOT NULL VARCHAR2(10)
DEPTNO NOT NULL VARCHAR2(10)
SAL VARCHAR2(10)
LOC VARCHAR2(10)

Note : empno and deptno is PK there is no FK


SQL> desc dept
Name Null? Type
----------------------------------------- -------- -----------------------
EMPNO NOT NULL VARCHAR2(10)
DEPTNO NOT NULL VARCHAR2(10)
DEPTNAME VARCHAR2(10)

Note : empno and deptno is PK there is no FK


Please let me know, where I am going wrong ????


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 10, 2006 9:05 am 
Newbie

Joined: Thu Jul 20, 2006 5:00 pm
Posts: 16
Even I tried to run from the command prompt just with setting hibernate jars in the classpath but it did not work.

Could any one please let me know what I am doing wrong.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 10, 2006 7:28 pm 
Newbie

Joined: Thu Jul 20, 2006 5:00 pm
Posts: 16
Finally, I am able to run it successfully. In the background my Oracle SQL Plus window was open, the moment I close and rerun it run successfully. I tried to diagnose the problem in different ways.
The problem happens only when I issued delete on both EMP and DEPT and let the SQL editor run in the background -> then tried to run -> it failed.
Once record is inserted, keep the sql window open it does not hurt hibernate.

But, am I only the person who get this kind of person ???

Its really weird ....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 10, 2006 7:30 pm 
Newbie

Joined: Thu Jul 20, 2006 5:00 pm
Posts: 16
But, am I only the person who get this kind of problem???


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.