-->
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.  [ 2 posts ] 
Author Message
 Post subject: is there any one online now who can help me with simple join
PostPosted: Wed May 03, 2006 4:16 pm 
Newbie

Joined: Thu Apr 27, 2006 6:20 pm
Posts: 10
is there any one online who can help me with simple join command...on messenger
thanks in advance
gautham


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 03, 2006 4:34 pm 
Newbie

Joined: Thu Apr 27, 2006 6:20 pm
Posts: 10
I am trying to display values from two simple tables with no primary keys and no foriegn keys but there is a common column.

Table EMPLOYEE - Columns ->ID,NAME,DEPTID
Table DEPARTMENT - Columns ->DEPTID,DEPTNAME

I tried like this:

Department.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="Employee" table="dep_test">
<id name="deptid" type="int"/>
<property name="deptname" type="string"/>
</class>
</hibernate-mapping>
********
Employee.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="Employee" table="emp_test">
<id name="id" type="int"/>
<property name="name" type="string"/>
<property name="deptid" type="int"/>
<one-to-one name="department" class="Department" />
</class>
</hibernate-mapping>
*******************


Employee.java
public class Employee implements Serializable
{
private String name;
private int deptid;
private int id;
public Employee() {}

public String getName() { return name; }

public void setName(String Name)
{
this.name = Name;
}

public int getDeptid() { return deptid; }

public void setDeptid(int Deptid)
{
this.deptid = Deptid;
}

public int getId() { return id; }
public void setId(int ID)
{
this.id = ID;
}

}


Deaprtment.java
import java.io.Serializable;
import java.util.Set;
import java.util.Iterator;

public class Department implements Serializable
{

private String deptname;
private int deptid;


public Department() {}

public String getDeptname() { return deptname; }

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

public int getDetid() { return deptid; }

public void setDeptid(int Deptid)
{
this.deptid = Deptid;
}

}


join.java

public class join
{
public static void main(String[] args)
{
BasicConfigurator.configure();
Logger logger = Logger.getLogger(insert.class);
Session session = null;
Transaction tx = null;
SessionFactory sessionFactory = null;

Configuration configuration = new Configuration();
configuration.configure();
sessionFactory = configuration.buildSessionFactory();
session = sessionFactory.openSession();
String query = "from Employee as emp left join emp.department as dept where emp.deptid=dept.deptid";
Query qry = session.createQuery(query);

Iterator prjItr = qry.iterate();
Employee currEmp = (Employee) prjItr.next();

System.out.println("++++++++++++"+currEmp.getDeptid());
System.out.println("+++++++++++"+currEmp.getId());

}}


got error as

"
BUILD FAILED
C:\working\build.xml:28: org.hibernate.PropertyNotFoundException: Could not find
a getter for department in class Employee"

Please help me in this


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