• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help With Associated Class in Hibernate Criteria Query  RSS feed

Jason Ferguson
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help with creating a criteria query with an associated class.

First, here is a partial implementation of a Project class:

And the Memo class:

In order words, there is a one-to-many relationship between Project and Memo (A project can have N memos, but a memo can only belong to one Project).

In the database schema, the T_PROJECTS and T_MEMOS tables are connected via the T_PROJECT_MEMO_LINK table. The T_PROJECT_MEMO_LINK has three fields: MEMOLINKID (Primary Key), PROJECTID, and MEMOID. The PROJECTID is the Primary Key for T_PROJECTS and MEMOID is PK for T_MEMOS.

What I want to do is create a getMemosByProject(Project project) in my DAO class. I implement my DAOs using Criteria rather than HQL (although I can handle HQL if I have to).

So, in my HibernateMemoDao class, I have this:

I'm unsure of the proper mapping annotations on the Project and Memo classes (whether it needs to be @OneToMany or @ManyToMany). I also don't think I have the syntax correct for the DAO getByProject() method.

Any help would be appreciated.

[ August 21, 2007: Message edited by: J. Ferguson ]
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!