1

When i run the code it gives me an exception:

org.hibernate.MappingException: element in configuration specifies no known attributes

I am not sure where error occurs, can anyone help me to solve this..

hibernate.cfg.xml

     <hibernate-configuration>
     <session-factory>
     <property name="hbm2ddl.auto">create</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">"url"</property>
<property name="hibernate.connection.username">"username"</property>
<property name="hibernate.connection.password">"password"</property>
<mapping resource="student.hbm.xml"/>
<mapping/>

Student.java

public class Student {

private String name;
 private int id;

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

}

Regular.java

 public class Regular extends Student {

String coursefees;

public String getCoursefees() {
    return coursefees;
}

public void setCoursefees(String coursefees) {
    this.coursefees = coursefees;
}

}

Distant.java

 public class Distant extends Student {

String distantfees;

public String getDistantfees() {
    return distantfees;
}

public void setDistantfees(String distantfees) {
    this.distantfees = distantfees;
}

}

student.hbm.xml

       <!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
       "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

       <hibernate-mapping>


       <class name="pojos.Student" table="student" discriminator-       value="student">  
       <id name="id" type="int">  
       <column name="id"/>
       <generator class="increment"></generator>  
       </id>  

       <discriminator column="type" type="string"></discriminator>  
       <property name="name" type="string">
       <column name="sname"/>
        </property>

     <subclass name="pojos.Regular" discriminator-value="regstud">  
     <property name="coursefees" type="string">
     <column name="coursefees"/>
     </property>  
    </subclass>   

   <subclass name="pojos.Distant" discriminator-value="distant">  
   <property name="distantfees" type="string">
  <column name="distfees"/>
  </property>  
  </subclass>

 </class>

 </hibernate-mapping>

Error:

Exception in thread "main" org.hibernate.MappingException: element in configuration specifies no known attributes at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2286) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2227) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2207) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2160) at org.hibernate.cfg.Configuration.configure(Configuration.java:2075)

0

1 Answer 1

3

remove that empty <mapping/> at the end of your hibernate.cfg.xml file

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.