Emanuel Kadziela wrote:If you look at a typical HQL query, i.e. (I copied this straight from the hibernate.org online docs)
you see that the query actually follows Java entity associations, NOT the relational table associations. That's how you have to structure the queries. Since you didn't list your java entity classes in your question, I can't tell how exactly this can be done in your example, but hopefully you get the idea.
The other thing to consider is using a native SQL query and helping hibernate translate that into the resulting java objects.
Yeah, I saw that too on the Hibernate site.
If you look at my previous posting from today, I've listed all the classes, database layout, etc.
In particular, how would you list all Students and their associated classes when the entity class for the M:M Resolver table (Studentcourse) looks like this:
Here's the query using the JPA fields in the classes:
This error occurs it looks like in the Studentcourse code below (see bold). I'm not totally sure...
Exception in thread "main" java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: COURSE_ID of: models.Studentcourse [Select s.studentName, c.courseName, c.courseId FROM models.Course as c, models.Student as s, models.Studentcourse as sc WHERE c.courseId = sc.[b]COURSE_ID AND s.STUDENT_ID = sc.STUDENT_ID ORDER BY s.STUDENT_NAME ASC, c.COURSE_NAME][/b]
-----
The code that's then failing, calling this query is:
I've tried using List<Studentcourse> ...., but that gives the same error as above.
This is really confusing.
I've been Googling all afternoon, but nothing is clicking yet...
Thanks,
-mike