This week's book giveaway is in the Reactive Progamming forum. We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line! See this thread for details.
This on the other hand throws a "state field path ...username cannot be resolved to a valid type" exception:
These are their relationships:
I seriously don't understand what's the problem. I assume the Course-User mapping is correct because I tried to persist a relationship with merge() and it worked. Also, when writing the Query I get autocompletion.
Alright, I thought of generating the entities in a new project to see if there's something wrong with my own entities. The only difference in the new project was that the Owner-Inverse were the other way around:
Doesn't fix the issue I'm having (it shouldn't anyway afaik) and still crashes the server. Here is a screenshot of the error: link.
So why didn't my previous query work? Why is the syntax so different? Because of the relationship needs a separate table?
Because it's a join.
Or, looking at it from a Java perspective, users is a List and so doesn't have a 'username' property.
Your first query (on Lecture) is against a single Course entity, so JPA/HQL has easy access to the 'title' property you are querying against, because courseid is a Course.
I have to admit I have wondered before now (after having fallen into just this thinking) what it is that prevents, eg, Hibernate from producing a JOIN itself based on a WHERE like that, but I expect it would be a bit of a 'mare for all but the most trivial of cases to ensure you produced a reasonable query.
You're right. I was taught (in uni DB course) to relate 3 tables like so "t1.id=tt.id and t2.id2=tt.id2" (tt being the join table). We barely touched JOIN. It makes sense now that I looked it up.
What doesn't make sense though (which is why I got confused in the first place), is that Netbeans autocompletes the "username" property when I wrote "course.users". So I thought "well hey, since it sees the mapping and knows what elements the List holds, it iterates the List and makes the join automatically so all is fine".
That was the issue all along it seems, when I wrote "course.uses.username" in the editor, it autocompleted the field. When I tried that statement in Netbeans' JPQL editor it obviously didn't work.
Eh, I got frustrated but now I know what happens, I'll just be extra careful next time