org.hibernate.MappingException: <mapping> 配置中的元素没有指定已知属性
org.hibernate.MappingException: <mapping> element in configuration specifies no known attributes
当我 运行 代码时,它给了我一个例外:
org.hibernate.MappingException: element in configuration specifies no known attributes
我不确定哪里出错了,谁能帮我解决一下..
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>
错误:
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)
删除 hibernate.cfg.xml 文件末尾的空白 <mapping/>
当我 运行 代码时,它给了我一个例外:
org.hibernate.MappingException: element in configuration specifies no known attributes
我不确定哪里出错了,谁能帮我解决一下..
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>
错误:
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)
删除 hibernate.cfg.xml 文件末尾的空白 <mapping/>