Spring & Hibernate’s not mapped problem

I’m sure that many hours must have been spent by Spring/Hibernate users trying to figure out why they are getting the table not mapped exception when they are sure that have mapped the table. Well the problem can be fixed if you take care of the case (upper vs. lower case). Suppose that the name of your table is user and the name of the your class is User.Here is the crux of the problem:This is the wrong version that leads to the not mapped exception:getHibernateTemplate().find("from user");Here is the correct version:getHibernateTemplate().find("from User");You see the problem is that in the hibernate version of the SQL, you are expected to use the name of your class and not the name of the table. Typically, the name of the table is all in lowercase and the name of the class starts with an uppercase. Yep programming can be very frustrating.

Advertisement

6 Responses to “Spring & Hibernate’s not mapped problem”

  1. Jay Says:

    I find this really bizarre. My mapping is

    so the query actually looks like

    s.createQuery(“from UserVO”)

    I’m sure the manual has good justification for this if I can find it.

  2. Jens Says:

    I have had the same problem, but I have also have to put the mapping in the hibernate.cfg.xml in the test/resource folder and in the application context of the test.

  3. Rossana Says:

    outch, I was hours trying. Thanks =)

  4. Jack Says:

    Thank youuuuuuuuu, it’s very helpful you saved my time))

  5. anitha Says:

    HI Shahram Javey
    THanks a lo…………….ot,I juist did the same mistake,was tryign to map to the table name and was breaking my head……..

    Keep up this good work and posting such useful advices

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

Please log in to WordPress.com to post a comment to your blog.

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.