• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

named queries can be defined only on an entity - problem

 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi there,

i have a new problem.
i have a domain object called "Lecture", and in the database its called "Lectures"
i want to use hibernate to manage this database stuff so i created the annotations:


the interpreter says:
named queries can be defined only on an entity or a mappedsuperclass class.
i have no idea whats the problem because with @entity i tell hibernate that its a entity, dont i?

ps.: and yes, i used the netbeans "do the magic"-create objects from database sheme ;)
 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there

I think that in this case you need to refer to Lecture in your named queries as Lecture because that is the name of the class. You never need to refer to the name of the table anywhere in your code (HQL included) with the exception of the @Table annotation or if you ever do plain sql queries (that is without hibernate).

Try changing your named queries to use the name of the class instead of the name of the table and see if that works.

Cheers,
Rachel
 
olze oli
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rachel,

thats what i tried first ;)
And no, it doesnt resolve the problem.
What's funny, everything works fine... as far as i can say (because the portlet is not finished yet).

Btw. i changed the database fields (from plural to singular) - imo it looks ugly now, but its working...

Any other ideas what could be the problem?
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, I'm interested to find out why this is. I'm busy putting an example together so that I can see what Hibernate does.

At what point do you get the error?
 
olze oli
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Netbeans only shows the error message.
If you'd like to i give you all the code + database layout
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the offer but I think I'll try further with a simple setup and see what I can find. I've put it together in IntelliJ and it's not showing any error messages so I'm going to try reading and writing some data with the queries and see how far I get.
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I set it up to store, retrieve and delete some lectures using the named query annotation that you had pasted above.

When running the code as is I got these errors

Then I changed one of the queries to use Lecture instead of Lectures and got an error on the other named query

and when I changed them both to be Lecture instead of Lectures there was no error.

So in the end the head of Lecture looked like this


Are you able to run your code at all or does the error from Netbeans prevent you from compiling and running it?




 
olze oli
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no i can compile and run the portlet fine (no it doesnt run fine, but thats because im absolutly new to hibernate, spring and struts)
the output of the sql querys looks also ok, like:



if you need further informations, just reply
maybe its just a netbeans bug?
 
Rachel Swailes
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it's generating the right sql for you then I think I'd be looking at if it's a problem with netbeans. I did a quick search and found this at Stack Overflow.
 
You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic