0

I am getting into java here. Fun and frustrating all at the same time :)

I have a simple method called showUsernames():

public String showUsernames(){
    TimesheetUserDAO su = new TimesheetUserDAO();
    Session session = su.getSession();
    setUsers(su.findByUsername(_users));
    session.close();
    return SUCCESS;
}

...however, I am having a time getting just the usernames out of the database. It is possible with the Hibernate DAO to get this correct? I am able to use su.findAll() and return everything.

Any thoughts? Need more code? Thanks :)

1 Answer 1

1

The DAO probably executee a request like

select u from User u where ...

Change the query to

select u.name from User u where ...

Of course, instead of having a List<User> as a result, you'll have a List<String>.

This is basic stuff described in the Hibernate reference documentation. Have you read it?

Also, getting the session from the DAO and closing it manually like this shows a design problem. This should be encapsulated by the service layer or, even better, by the declarative transaction handling.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the note. I'll read over the documentation some more.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.