Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The state field path cannot be resolved to a valid type

 
Vasilis Souvatzis
Ranch Hand
Posts: 81
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to ask, this is driving me crazy...

The following statement works wonderfully:


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.

edit: I've seen this similar thread on Coderanch and also this stackoveflow thread but I don't think there are any errors with my table names and variable names...
 
Dave Tolls
Ranch Hand
Posts: 2095
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does your User class look like?
Does it have a 'username' field?
 
Vasilis Souvatzis
Ranch Hand
Posts: 81
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeap, it does have a username.

 
Vasilis Souvatzis
Ranch Hand
Posts: 81
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vasilis Souvatzis
Ranch Hand
Posts: 81
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Silly me, that Query syntax isn't the proper way to relate the entities... This is:


I hereby declare this problem... RESOLVED!
 
Dave Tolls
Ranch Hand
Posts: 2095
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vasilis Souvatzis wrote:Silly me, that Query syntax isn't the proper way to relate the entities... This is:


I hereby declare this problem... RESOLVED!


I was just going to post about a JOIN.
No, seriously.
 
Vasilis Souvatzis
Ranch Hand
Posts: 81
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hehehe, I believe you

So why didn't my previous query work? Why is the syntax so different? Because of the relationship needs a separate table?

 
Dave Tolls
Ranch Hand
Posts: 2095
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vasilis Souvatzis wrote:Hehehe, I believe you

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.
 
Vasilis Souvatzis
Ranch Hand
Posts: 81
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic