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.
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.
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.
Thank you!!! I made the same mistake. Importing hibernate stuff seemed the obvious choice to me. Doh.
thanks, same error and your blog post was the first google hit 🙂
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… 😉
Mate,
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…
Cheers,
S.
Thanks a lot, same issue and i guess i would have search for a long time .. 🙂
Thanks Panos for the post… it really helped me…
Thank You!!!! (and also thanks Google for let me find this blog) You save my day.
cheers
Same problem here. Thanks for the post!
Subtle! Saved me a few hours of head scratching, so I’d like to add my thanks too.
thanks!!
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
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…
Thanks!1…same thing happened to me too.
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.
Same thing’s happening to me, but I’m using javax.persisence.entity. *sigh*
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.
Thanks a lot. You saved a lot of time.
thanks man !!! I had the same problem…
thanks also from me
But what if we want to use hibernate @Entity attribute like ‘dynamicUpdate’?
:* ! You saved me a lot of hours ! Thank you !
Thanks so muck for your help. I would have worked on this forever.
Thank you! You just saved me hours of my life!
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
THANK YOU! THANK YOU! THANK YOU!
I already wasted a few hours on this, but better later then never! 😉
thanks , that saved me a lot of time.
very helpful post !
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.
Tahnk you very much for this post. I had the same problem.
Cheers Mate, what a fcuk… Hate those stupid mistakes… Greets
Thank you very much for your post
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.
A million thanks. You saved me. I made the exact same error.
More thanks! Was getting frustrated before I found this post. I owe you a couple of hours from my life!
Gotcha! 🙂 Thank you a lot for the solution!
Thank you, this saved me 🙂
That was very helpful and timely. Thanks!
You’ve saved my life with this post.
I was about giving up Hibernate…
In few lines, you solved my problem.
I’ll translate your post to PT_br for help more people.
thanks.
PT_br version: http://leandron.wordpress.com/2010/04/04/hibernate-troubleshooting-1-org-hibernate-mappingexception-unknown-entity/
Hello Leandro, thanks for sharing the post.
Thank you sooooooooooo much for saving me the trouble of searching for hours for the mistake.
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/
Oh boy, I did the same mistake!
thanx
Thank you! This saved me lots of time.
Thanks, I wasted almost a day with out searching for it.
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.
Thank you! This just saved me a couple of hours 🙂
Thank you very much. It also saved me.
dude you saved me an hour of debugging.. at least
You’re a livesaver, thanks!
+1
Thanks a ton , you saved a lot of time of mine with this post.
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
Spent total 5 hours on this stupid bug!! lol..thanks for posting solution 🙂
thanks a lot it saved my lot of time..
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)
oracle.jdbc.driver.OracleDriver
password
jdbc:oracle:thin:@localhost:1521:xe
login
org.hibernate.dialect.Oracle10gDialect
true
org.hibernate.transaction.JDBCTransactionFactory
update
package essai;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class Ecole {
@Id
private int id_ecole;
private String nom_ecole;
@Id
public int getId_ecole() {
return id_ecole;
}
.
.
.
.
}
Thank you ! It really helped me !
Thanks man you are g8
thanks a lot man!!!
Thank u same problem i was try from last one day……. Thanks a lotttttt
Thanks, JPA/Hibernate noob, did not spend two hours thanks to you and google.
Even though i have used Java import files am getting org.hibernate.MappingException: Unknown entity:…..
can u please solve it !!!