aspose file tools*
The moose likes Object Relational Mapping and the fly likes Could not read mappings from resource(Mapping issue) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Could not read mappings from resource(Mapping issue)" Watch "Could not read mappings from resource(Mapping issue)" New topic
Author

Could not read mappings from resource(Mapping issue)

Ranendra Kumar
Greenhorn

Joined: Sep 27, 2012
Posts: 5
Following error i am getting in my hibernate program...attaching errors,hbm file and cfg

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
org.hibernate.MappingException: Could not read mappings from resource: com/jlcindia/hibernate/Student.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1296)
at com.jlcindia.hibernate.CHibernateUtil.<clinit>(CHibernateUtil.java:10)
at com.jlcindia.hibernate.CLab4Client.main(CLab4Client.java:12)
Caused by: org.hibernate.PropertyNotFoundException: field not found: qualification
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.createProperty(HbmBinder.java:2138)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2115)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2005)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:368)
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.addResource(Configuration.java:482)
... 8 more
java.lang.NullPointerException
at com.jlcindia.hibernate.CLab4Client.main(CLab4Client.java:13)



--------------------------------------------------------------------------------------------

-----------------------------------------------------------------------
my cfg code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">altruist</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/jlcdb1</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="myeclipse.connection.profile">mysqlDriver</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="show_sql">true</property>

<property name="hbm2ddl.auto"> update</property>
<mapping resource="com/jlcindia/hibernate/Student.hbm.xml"/>
</session-factory>
</hibernate-configuration>
-----------------------------------------------------------------------------------------------------------
using a package:com.jlcindia.hibernate and kept hbm in the same pkg and cfg in src directory,still facing problem while running the code..please anyone solve this issue!
if you need hbm.xml then here it is:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.jlcindia.hibernate">
<class name="Student" table="mystudents">
<id name="sid" column="sid" type="int">
<generator class="increment"/>
</id>
<property name="sname" />
<property name="dob" />
<property name="qualification"/>

<array name="courses" table="courses">
<key column="sid" />
<index column="idx" />
<element column="ename" type="String" />
</array>

<list name="emails" table="emails">
<key column="sid" />
<index/>
<element column="emailID" type="String" />
</list>

<bag name="marks" table="marks">
<key column="sid" />
<element column="marks" type="int" />
</bag>

<set name="phones" table="phones">
<key column="sid" />
<element column="phoneNo" type="long" />
</set>

<map name="refs" table="refs">
<key column="sid" />
<index column="rname" type="String"/>
<element column="rphone" type="long" />
</map>
</class>
<filter-def name="titleFilter">
<filter-param name="titleParam" type="string" />
</filter-def>

</hibernate-mapping>
----------------------------------------------------------------------------------------------
Reddy Prashanth
Ranch Hand

Joined: Aug 09, 2005
Posts: 61
Can you post your Student.java code here. I suspect, the below property is missing in the java class.

<property name="qualification"/>
Ranendra Kumar
Greenhorn

Joined: Sep 27, 2012
Posts: 5
thanks for replying Reddy Prashanth !here is my Student.java
package com.jlcindia.hibernate;

import java.util.*;

public class Student {

private int sid;
private String sname;

private String dob;
private String qualifiaction;

private String[]courses;

private List<String> emails;

private List<Integer> marks;


private Set<Long> phones;

private Map<String, Long> refs;

public Student(String sname, String dob, String qualifiaction,
String[] courses, List<String> emails, List<Integer> marks,
Set<Long> phones, Map<String, Long> refs) {
super();
this.sname = sname;
this.dob = dob;
this.qualifiaction = qualifiaction;
this.courses = courses;
this.emails = emails;
this.marks = marks;
this.phones = phones;
this.refs = refs;
}

public int getSid() {
return sid;
}

public void setSid(int sid) {
this.sid = sid;
}

public String getSname() {
return sname;
}

public void setSname(String sname) {
this.sname = sname;
}

public String getDob() {
return dob;
}

public void setDob(String dob) {
this.dob = dob;
}

public String getQualifiaction() {
return qualifiaction;
}

public void setQualifiaction(String qualifiaction) {
this.qualifiaction = qualifiaction;
}

public String[] getCourses() {
return courses;
}

public void setCourses(String[] courses) {
this.courses = courses;
}

public List<String> getEmails() {
return emails;
}

public void setEmails(List<String> emails) {
this.emails = emails;
}

public List<Integer> getMarks() {
return marks;
}

public void setMarks(List<Integer> marks) {
this.marks = marks;
}

public Set<Long> getPhones() {
return phones;
}

public void setPhones(Set<Long> phones) {
this.phones = phones;
}

public Map<String, Long> getRefs() {
return refs;
}

public void setRefs(Map<String, Long> refs) {
this.refs = refs;
}



}
Reddy Prashanth
Ranch Hand

Joined: Aug 09, 2005
Posts: 61
See the difference .. both are not same

private String qualifiaction;

<property name="qualification"/>


Ranendra Kumar
Greenhorn

Joined: Sep 27, 2012
Posts: 5
so silly mistake done by me...hey thanks a ton!but other issue is:
(org.hibernate.MappingException: Could not determine type for: String, for columns: [org.hibernate.mapping.Column(emailID)])
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Could not read mappings from resource(Mapping issue)
 
Similar Threads
InvalidMappingException
duplicate Mapping Exception : duplicate collection role mapping
org.hibernate.InvalidMappingException: Could not parse mapping document from resource customercare.h
hibernate error
hibernate hello world