• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help in Hibernate

 
Paul Michael Serrano
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, I would like to ask how will I create this in Hibernate

select rd.*, re.*, (select count(1) from SURVEY where reporterid =
rd.reporterid) tw,
from REPORTER rd, REPORTER_EXTRA re
where rd.reporterid=re.reporter_id and rd.reportertype = 'C'
order by rd.name


I have 3 tables there
REPORTER, REPORTER_EXTRA and SURVEY table

The REPORTER and REPORTER_EXTRA has a one-to-one relationship
and also for SURVEY since I'm getting the count with respective reporterid(which is the primary key of REPORTER and foreign key of SURVEY).

I've got this code snippets,

.....

Reporter.hbm.xml --> maps to Reporter.class

<property name="tw" formula="select count(1) from survey s where reporterid = s.reporterid "/>
<one-to-one name="repExtra" constrained="true" class="com.beans.ReporterExtra"/>

.......

//hibernate code

Session sess = HibernateUtil.getSessionFactory().openSession();
results = sess.createCriteria(Reporter.class)
.add(Restrictions.eq("reporterType", "C"))
.addOrder(Order.asc("name")).list();
sess.close();


......

Am I doing the right thing?

Paul
 
Paul Michael Serrano
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot to put this one in my bean Reporter.class I have this attribute

private long tw;

that tw has a getter and setter in my Reporter.class


Reporter.hbm.xml --> maps to Reporter.class

<property name="tw" formula="select count(1) from survey s where reporterid = s.reporterid "/>
<one-to-one name="repExtra" constrained="true" class="com.beans.ReporterExtra"/>
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a compile error or exception you are getting? When you run the criteria, do you see the SQL? Set your log4j.properties file to debug for Hibernate and see if you get anything.

Let us know.

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic