• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Could not read mappings from resource ?

 
Ayub ali khan
Ranch Hand
Posts: 394
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Please help me with the following problem











==================================================================
Following Error message when run using store as the initial argument.

============================================================

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Initial SessionFactory creation failed.org.hibernate.MappingException: Could not read mappings from resource: com/ibm/hibernate_article/Employee.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at com.ibm.util.HibernateUtil.<clinit>(HibernateUtil.java:31)
at com.ib.hibernate_article.EmpManager.createAndStoreEmp(EmpManager.java:32)
at com.ib.hibernate_article.EmpManager.main(EmpManager.java:25)
Caused by: org.hibernate.MappingException: Could not read mappings from resource: com/ibm/hibernate_article/Employee.hbm.xml
at org.hibernate.cfg.Configuration.addClass(Configuration.java:506)
at com.ib.util.HibernateUtil.<clinit>(HibernateUtil.java:27)
... 2 more
Caused by: org.hibernate.PropertyNotFoundException: field not found: empName
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:97)
at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:104)
at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:112)
at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:89)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:77)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:410)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:343)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:282)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153)
at org.hibernate.cfg.Configuration.add(Configuration.java:386)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
at org.hibernate.cfg.Configuration.addClass(Configuration.java:503)
... 3 more


Best Regards
Ayub

[ October 19, 2006: Message edited by: Ayub ali khan ]

[Editied to use code tags - Paul Sturrock]
[ October 25, 2006: Message edited by: Paul Sturrock ]
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in case this is still a problem:
you have a space in the property name:

<id name=" empName " column="EMPNAME">

should be

<id name="empName " column="EMPNAME">



pascal
 
FX Douxchamps
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you need to check the place you put the mapping file...

The package location must be the same than the java file...
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Plus, you can't have the same attribute be your id and a property at the same time.

I would keep EMPNAME as a property and not make it an ID, it is a really bad candidate for an ID, because you could have two Joe Smith's in your database and then you are in trouble. Always make your ids, as the following

1. a Long
2. named id
3. not a business field in your database, let the database use its native incrementor, whatever that is. This is called a surrogate key, and has no business meaning to it, like EMPNAME does.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic