Home > Hibernate, Java > org.hibernate.MappingException: Unknown entity: AFullyQualifiedClassName

org.hibernate.MappingException: Unknown entity: AFullyQualifiedClassName

This is actually very annoying. I spent two hours trying to find out why I was getting this error message while using annotations to declare my entity bean. I checked everything, the hibernate configuration file, I made sure my annotated class was declared and added to the AnnotationConfiguration I was using and I also made sure that I had the fully qualified class name in my classpath. I (thought that I) made sure everything was ok but I was still getting this error message.

At last I found out that I had accidentally used the wrong annotation with my entity class. When I declared my class to be an entity bean (a persistent POJO), by using the @Entity annotation, I had accidentally imported the org.hibernate.annotations.Entity class instead of the correct one javax.persistence.Entity. I used the auto-complete Eclipse feature and somehow I imported the wrong package.

Categories: Hibernate, Java
  1. 23 July 2008 at 1:40 am

    You, as they say, are Da Man.

    I suppose I should have known better, but I just wasted a good number of minutes repeatedly failing to notice exactly this mistake in the auto-IDE-imported-and-then-folded imports section at the top of my source file…

    I’d been spelunking through the bowels of my Spring XML config files, hibernate.cfg.xml, etc., wondering what I’d messed up and whether these annotations really save any work at all if I can bungle a case of “Hello, World!”-level triviality with such thoroughness as I had seemed to…

    Thanks for the helpful post. It prodded me to look somewhere that I’d overlooked while seeking a more difficult solution to a presumably nastier problem.

  2. Paul
    20 August 2008 at 7:32 pm

    Thanks, this just happened to me too.

    I already had mapped my class in the spring config file, along with a bunch of other classes that worked and I was tearing my hair out. I didn’t waste a few minutes, rather a couple of hours on an already overdue project, but at least this gave me a hint of where to look.

  3. Javadude
    21 August 2008 at 8:19 am

    Thank you!!! I made the same mistake. Importing hibernate stuff seemed the obvious choice to me. Doh.

  4. Core-Dump
    4 October 2008 at 8:17 pm

    thanks, same error and your blog post was the first google hit 🙂

  5. 7 October 2008 at 4:34 am

    Thanks so much! I don’t know if I ever would have guessed that… the org.hibernate.annotations.Entity import seemed completely appropriate. I wish I had found your post sooner… 😉

  6. Simon
    17 October 2008 at 3:07 am


    thank you! It took me 6 hours to find this on my example. I even debugged my way through the ConfigurationLoader to see why it wouldn’t load the class.

    Same issue. Autocompleted my way through to the hibernate annotation import.

    Then I found this post on google. Otherwise I would still debug…



  7. 28 October 2008 at 4:54 pm

    Thanks a lot, same issue and i guess i would have search for a long time .. 🙂

  8. Adrian
    29 November 2008 at 4:19 pm

    Thanks Panos for the post… it really helped me…

  9. Ariel
    10 December 2008 at 1:10 pm

    Thank You!!!! (and also thanks Google for let me find this blog) You save my day.

  10. 27 January 2009 at 12:42 am

    Same problem here. Thanks for the post!

  11. Chrisl
    6 February 2009 at 1:22 pm

    Subtle! Saved me a few hours of head scratching, so I’d like to add my thanks too.

  12. 5 March 2009 at 8:04 pm


  13. dEEPAK
    10 March 2009 at 4:00 pm

    Thanks a lot , I should have googled the error instead of trying to figure it out myself. Anyways, you save me a lot of effort

  14. 11 March 2009 at 5:28 pm

    Yet another comment of thanks! All of the solutions I saw mentioned deploying a persistance.xml file for testing which didn’t seem right to me…

  15. 16 March 2009 at 8:57 pm

    Thanks!1…same thing happened to me too.

  16. Marcus
    18 March 2009 at 1:21 pm

    To join the club, i´ve done this twice now and never seem to learn. Staring at the entity which failed for around 10 minutes before i started up google.

  17. nil
    23 March 2009 at 8:48 pm

    Same thing’s happening to me, but I’m using javax.persisence.entity. *sigh*

  18. dr_jerry
    6 April 2009 at 9:56 pm

    Man just came back from Holiday without internet, and spend some of my spare time at hunting this stupid bug, with your post it was solved within seconds.

  19. Johannes
    11 April 2009 at 12:51 am

    Thanks a lot. You saved a lot of time.

  20. stachu
    17 April 2009 at 1:00 pm

    thanks man !!! I had the same problem…

  21. egifford
    28 April 2009 at 3:17 pm

    thanks also from me

    But what if we want to use hibernate @Entity attribute like ‘dynamicUpdate’?

  22. Stefan
    4 May 2009 at 11:39 am

    :* ! You saved me a lot of hours ! Thank you !

  23. herb
    22 May 2009 at 6:20 pm

    Thanks so muck for your help. I would have worked on this forever.

  24. Ben
    30 May 2009 at 4:53 am

    Thank you! You just saved me hours of my life!

  25. prasad iyer
    12 June 2009 at 10:37 pm

    Saved by the bell. This post should have being 1st result in google search. Are we missing any tags over here.

    Thanks for the great post

  26. Mihai
    23 June 2009 at 3:36 pm


    I already wasted a few hours on this, but better later then never! 😉

  27. livp
    9 July 2009 at 7:23 am

    thanks , that saved me a lot of time.
    very helpful post !

  28. Henrik Winther Jensen
    25 July 2009 at 6:14 pm

    Thanks are in order indeed, but who was the guy that created this trap that caught a bunch of obviously quite clever people?

    And why did he do it?

    Not malice for sure, Stupidity maybe? nope, a stupid person could not create software like this, My guess is: naivety. Failure to consider the consequence of his actions.

  29. Thank you
    28 July 2009 at 11:53 am

    Tahnk you very much for this post. I had the same problem.

  30. rob
    13 October 2009 at 7:57 am

    Cheers Mate, what a fcuk… Hate those stupid mistakes… Greets

  31. Stefanos
    21 October 2009 at 8:47 am

    Thank you very much for your post

  32. 7 November 2009 at 6:20 pm

    Awesome! Although wasted a lot of time doing so many things (thinking AnnotationConfiguration is buggy and replaced that with spring AnnotationSessionFactoryBean as suggested in some other forum), finally this change did the trick.

  33. 12 November 2009 at 2:23 am

    A million thanks. You saved me. I made the exact same error.

  34. Lemule
    12 December 2009 at 4:45 am

    More thanks! Was getting frustrated before I found this post. I owe you a couple of hours from my life!

  35. Zheka
    18 December 2009 at 6:19 pm

    Gotcha! 🙂 Thank you a lot for the solution!

  36. Girts
    12 January 2010 at 3:16 am

    Thank you, this saved me 🙂

  37. Praful
    16 February 2010 at 7:38 am

    That was very helpful and timely. Thanks!

  38. Thank You!!
    29 March 2010 at 3:16 pm

    You’ve saved my life with this post.

    I was about giving up Hibernate…

  39. 4 April 2010 at 10:01 pm

    In few lines, you solved my problem.
    I’ll translate your post to PT_br for help more people.


  40. Leandro Nunes
  41. 7 April 2010 at 8:49 am

    Hello Leandro, thanks for sharing the post.

  42. Thomas
    5 May 2010 at 4:09 pm

    Thank you sooooooooooo much for saving me the trouble of searching for hours for the mistake.

  43. nimana
    24 May 2010 at 9:35 pm

    The root of this exception is, that the entity hibernate is trying to load, is either not configured at all or not configured correctly. We use *.hbm.xml files to map entities and saw this error because we missed to map one of the entities. Check: http://nimana.wordpress.com/2010/05/24/hibernate-mappingexception-persistent-class-not-known/

  44. Al
    15 January 2011 at 9:17 pm

    Oh boy, I did the same mistake!

  45. MikeD
    17 January 2011 at 8:16 am

    Thank you! This saved me lots of time.

  46. Ravi
    18 February 2011 at 10:25 am

    Thanks, I wasted almost a day with out searching for it.

  47. djcasti
    16 May 2011 at 8:04 pm

    Hey guys,

    I come to you because i have the same error but my entity class has imported the correct class (javax.persistence.Entity).

    My entity is also correctly mapped on the hibernate.cfg.xml file.

    i don’t know what is happend with this.

    Please, any help thank you.

  48. Koen
    10 June 2011 at 2:20 pm

    Thank you! This just saved me a couple of hours 🙂

  49. Eunice
    1 July 2011 at 9:15 am

    Thank you very much. It also saved me.

  50. AFG
    26 July 2011 at 10:29 am

    djcasti :
    Hey guys,
    I come to you because i have the same error but my entity class has imported the correct class (javax.persistence.Entity).
    My entity is also correctly mapped on the hibernate.cfg.xml file.
    i don’t know what is happend with this.
    Please, any help thank you.

  51. Vitez
    20 August 2011 at 10:34 pm

    dude you saved me an hour of debugging.. at least

  52. Matthias
    7 September 2011 at 9:08 am

    You’re a livesaver, thanks!

  53. mo
    12 October 2011 at 12:39 pm


  54. Raj
    12 December 2011 at 12:07 pm

    Thanks a ton , you saved a lot of time of mine with this post.

  55. 6 January 2012 at 6:22 am

    here i imported correct file
    but still i hav same error
    can u tell me about cfg.xml file
    because i am new for hibernate
    thanks in advance

  56. 25 January 2012 at 10:58 pm

    Spent total 5 hours on this stupid bug!! lol..thanks for posting solution 🙂

  57. Prabhakar
    14 February 2012 at 1:44 pm

    thanks a lot it saved my lot of time..

    • Happy
      15 March 2012 at 1:53 pm

      I come to you because i have the same error but my entity class has imported the correct class (javax.persistence.Entity).
      My entity is also correctly mapped on the hibernate.cfg.xml file.
      i don’t know what is happend with this.
      Please, any help thank you.

      Exception in thread “main” org.hibernate.MappingException: Unknown entity: essai.Ecole
      at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:580)
      at org.hibernate.impl.SessionImpl.getEntityPersister(SessionImpl.java:1365)
      at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
      at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
      at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
      at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
      at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
      at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
      at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:562)
      at org.hibernate.impl.SessionImpl.save(SessionImpl.java:550)
      at org.hibernate.impl.SessionImpl.save(SessionImpl.java:546)
      at essai.GestionEcole.ajouteEcole(GestionEcole.java:14)
      at essai.GestionEcole.main(GestionEcole.java:22)


      package essai;

      import javax.persistence.Entity;
      import javax.persistence.Id;

      public class Ecole {

      private int id_ecole;
      private String nom_ecole;

      public int getId_ecole() {
      return id_ecole;


  58. cwaadd
    18 April 2012 at 8:36 am

    Thank you ! It really helped me !

  59. jitendra
    11 May 2012 at 5:31 am

    Thanks man you are g8

  60. ut
    29 May 2012 at 5:12 pm

    thanks a lot man!!!

  61. suk
    20 September 2012 at 5:34 pm

    Thank u same problem i was try from last one day……. Thanks a lotttttt

  62. jhunsinger
    2 November 2012 at 4:43 pm

    Thanks, JPA/Hibernate noob, did not spend two hours thanks to you and google.

  63. Smaran
    29 November 2012 at 1:40 pm

    Even though i have used Java import files am getting org.hibernate.MappingException: Unknown entity:…..
    can u please solve it !!!

  1. 19 November 2009 at 10:58 am
  2. 4 April 2010 at 10:16 pm
  3. 24 May 2010 at 9:33 pm
  4. 26 September 2014 at 12:50 am

Leave a Reply

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

WordPress.com Logo

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

Google photo

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

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

%d bloggers like this: