Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA - need help with query

 
Robert Tomson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, i am working on recreating tree from database table,



what i need to do is to select all items where parentIndex is null

so in mysql i can do : SELECT * FROM `treemenu` WHERE parentIndex IS NULL

how should query look like in jpa to get same results ?

"SELECT t FROM TreeMenu t WHERE t.parentIndex IS NULL" gives me 'unknown state or association field [parentIndex]'
 
Joe carco
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please show us your entity code and its mappings / annotations
 
Robert Tomson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it was automatically generated by netBeans

 
Joe carco
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using JPA Query Language or Native Query Language?
 
Joe carco
Ranch Hand
Posts: 82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using JPQL, try this



in your query youre using a database column. I assume you are using JPQL, there the atabase column "parentindex" correctly causes that exception
 
Robert Tomson
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much , its working, haha now when i know the answer its seams logical :P
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic