question on database query using hibernate in java with annotations
Posted
by molleman
on Stack Overflow
See other posts from Stack Overflow
or by molleman
Published on 2010-05-31T12:08:07Z
Indexed on
2010/05/31
12:13 UTC
Read the original article
Hit count: 290
Hello, simple question regarding HQL(Hibernate query language)
so i have user class , that can hold a list of Projects, how do i take this out of the database depending on a username,
this is how i take out my user
String username = "stephen";
YFUser user = (YFUser) session.createQuery("select u FROM YFUser u where u.username = :username").setParameter("username", name).uniqueResult();
but i want to take out the list of projects
here is the projects list within the class YFUser(my user class);
how would i query the database to get this list of projects @Entity @Table(name = "yf_user_table") public class YFUser implements Serializable,ILightEntity {
.........
@OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY)
@JoinTable(name = "YFUSER_JOIN_PROJECT", joinColumns = {
@JoinColumn(name = "user_id") }, inverseJoinColumns = {
@JoinColumn(name = "project_id") })
private List<Project> projects = new ArrayList<Project>();
© Stack Overflow or respective owner