• Post Reply Bookmark Topic Watch Topic
  • New Topic

mapping problem  RSS feed

 
Ranch Hand
Posts: 85
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have a mapped entity called useraccount, you have one called Login.
 
pradeep gamage
Ranch Hand
Posts: 85
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 85
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



useraccountTable.jpg
[Thumbnail for useraccountTable.jpg]
useraccount table
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for replaying.
but i am not using sql. i am using hql
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!