could anybody help about n to n mapping in hibernate please(between
2 tables and the 3th one which is the relation between them) .
I tried to read from the 3th table then to complete the query but it
returns empty.
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"hibernate.sourceforge.net/...rnate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="eg.Relation" table="tblRelation" >
<composite-id>
<key-many-to-one name="codeformTable1" class="eg.Table1"
column="codeformTable1"/>
<key-many-to-one name="codeformTable2" class="eg.Table2"
column="codeformTable2"/>
</composite-id>
<property name="fieldTable3" column="fieldTable3"
type="java.lang.Integer" />
</class>
</hibernate-mapping>
package general;
import java.util.List;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.ObjectNotFoundException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.Hibernate;
public class CService
{
private static CService instance = null;
private CService()
{
}
public static synchronized CService getInstance()
{
if (instance == null)
{
instance = new CService();
}
return instance;
}
public List getCList(String s)
{
Session session = ConnectionFactory.getInstance
().getSession();
try
{
Query query =session.createQuery("select c
from eg.Relation c ");
if((query.list()).isEmpty() )
System.out.println("empty");
return query.list();
}
catch (HibernateException e)
{
System.err.println("Hibernate Exception" +
e.getMessage());
throw new RuntimeException(e);
}
finally
{
if (session != null)
{
try
{
session.close();
}
catch (HibernateException e)
{
System.err.println
("Hibernate Exception" + e.getMessage());
throw new RuntimeException
(e);
}
}
}
}
}
.jsp
<%
List cList = CService.getInstance().getCList(s);
request.setAttribute("cList", cList);
if (cList.isEmpty())
System.out.println("empty_2");
%>