This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes mapping problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "mapping problem" Watch "mapping problem" New topic
Author

mapping problem

pradeep gamage
Ranch Hand

Joined: Aug 03, 2009
Posts: 85

I am using hibernate for my project.
so when i run project its giving error massage like this

org.hibernate.hql.ast.QuerySyntaxException: useraccount is not mapped [from useraccount a where a.User_UserID like 'u%']





i am using hibernate annotation. when i insert data into database its run without errors.for insert i used session.save() method.but i wrote hql query to get data from database.when i run project it's giving error as above.

this is my Login.java class that used to map database table.


can any one post comment to solve this error.
thanks


Software Engineer(BSC):SCJP 1.5
(Knowledge is power when applied)
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You don't have a mapped entity called useraccount, you have one called Login.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
pradeep gamage
Ranch Hand

Joined: Aug 03, 2009
Posts: 85

useraccount is table name. Login is class that map with useraccount.
Mr.Paul Sturrock can you give example code that i can use for retrieve data from database by using hibernate.

thanks.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


useraccount is table name. Login is class that map with useraccount.


The exception tells me you are using this as your HQL query:


useraccount is the table, not the object. HQL works with objects.

There are quite a lot of examples in the Hibernate documentation if you need them.
pradeep gamage
Ranch Hand

Joined: Aug 03, 2009
Posts: 85

I am going to create Login.
so I have to get username and password from useraccount table.

this is class that map with useracount table


and i used following code fragment to take data from database table called useraccount.


when i run this it gives above mention error.






[Thumbnail for useraccountTable.jpg]

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You are still trying to query an unmapped entity, for the reason I mentioned above. Remember in Hibernate you are not using SQL.

I think its probably worth spending a few hours reading the documentation.
pradeep gamage
Ranch Hand

Joined: Aug 03, 2009
Posts: 85

thanks for replaying.
but i am not using sql. i am using hql
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Indeed. So if you use HQL you need to query the mapped class, not the table. You have a mapped class called Login.

(and if you are not intending to use SQL, why define your variable contain the query as SQL_QUERY?)
 
GeeCON Prague 2014
 
subject: mapping problem