tags:

views:

48

answers:

1

I have a Project class that has a Set of userstories called userStories12many. I'm having troubles trying to get the project that has a certain userstory in its set getComponent(int userStoryID)

I think im on the right track but i dont know what i did wrong

public Projects getComponent(int userStoryID) {
    Session session = SessionFactoryHelper.getSessionFactory()
    .getCurrentSession();
    session.beginTransaction();

    List<Projects> compo = session.createQuery("select p "
    + "from Projects as p inner join fetch p.userStories12many as u "
    + "where u.storyId='" + userStoryID + "'").list();
    session.getTransaction().commit();
    return compo.get(0);

}
A: 

There are a few thing that feel wrong to me in your code:

  1. It's better to bind parameters rather than inserting their value directly in the query string.
  2. How come the id is quoted? isn't it an int?
  3. You are accessing the query results after the transaction is ended which is often a bad idea
Maurice Perry
Ive fixed your last two points but its still not working. It returning null.
mslatf