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.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

The state field path cannot be resolved to a valid type

 
Ranch Hand
Posts: 109
1
Netbeans IDE Chrome Java
  • 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...
 
Rancher
Posts: 4258
47
  • 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: 109
1
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeap, it does have a username.

 
Vasilis Souvatzis
Ranch Hand
Posts: 109
1
Netbeans IDE Chrome Java
  • 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: 109
1
Netbeans IDE Chrome Java
  • 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
Rancher
Posts: 4258
47
  • 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: 109
1
Netbeans IDE Chrome Java
  • 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
Rancher
Posts: 4258
47
  • 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: 109
1
Netbeans IDE Chrome Java
  • 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
 
Proudly marching to the beat of a different kettle of fish... while reading this tiny ad
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!