• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Hibernate - can't get the collection (List) when create criteria

 
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Department Employee relationship (department has employeeS)


when I query for employee - I can get the department *Name* //name name of department is not unique (department_id is unique)




BUT when I do this


I don't get the list of all employees, why?

Employee:


and Department


Thank you!
 
author and cow tipper
Posts: 5000
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And I'm safely assuming you've left out the getter methods just not to pollute the page, right? Yeah, I thought so.

In my Hibernate Made Easy book, I have a little example that uses the "Team has Players" scenario. The two classes are mapped as so:







In this scenario, I have no problem pulling out both sides of the relationship using a Criteria query. Do you see any major differences between your code and mine?

Mapping Bi-Directional One-To-Many Relationships with Hibernate

You are indeed getting departments back from your query, right? How many departments get returned when you size the list? (Just making sure stage one works before digging too deep).

-Cameron McKenzie


 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Cameron for the insight!

1. I corrected the code (annotation) on Employee and added


2. per your question:
*You are indeed getting departments back from your query, right? How many departments get returned when you size the list? (Just making sure stage one works before digging too deep).

YES! I get 3 departments
the code:

consult output:


you can see that there are no empls in the department, it says total 0...(but there are, when I run ListEmployees I can see what department he belongs to)

 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic