我是初学者练习hibernate ORM,我需要帮助解决以下异常: 谢谢
Entitiy:
package com.ds.supercar.model.usermodel;
公共类地址{
private String emailid;
private String mobile;
private String street;
private String city;
private String state;
private String country;
private String pin;
//GETTERS AND SETTERS
public Address() {
// TODO Auto-generated constructor stub
}
public Address(String emailid, String mobile, String street, String city, String state, String country,
String pin) {
super();
this.emailid = emailid;
this.mobile = mobile;
this.street = street;
this.city = city;
this.state = state;
this.country = country;
this.pin = pin;
}
public String getEmailid() {
return emailid;
}
public void setEmailid(String emailid) {
this.emailid = emailid;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getPin() {
return pin;
}
public void setPin(String pin) {
this.pin = pin;
}
}
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="com.ds.supercar.model.usermodel.Address" table="supercaraddress" schema="supercar">
<id column="email"/>
<property name="mobile"/>
<property name="street"/>
<property name="city"/>
<property name="state"/>
<property name="country"/>
<property name="pin"/>
</class>
</hibernate-mapping>
hibernate cfg xml:
<!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.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:SYSTEM</property>
<property name="hibernate.connection.username">system</property>
<property name="hibernate.connection.password">admin</property>
<property name="hbm2ddl_auto">create</property>
org.hibernate.dialect.Oracle11gDialect 真正
例外:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN请正确初始化log4j系统。 初始SessionFactory创建失败:org.hibernate.MappingException:读取资源时出错:com / ds / supercar / resources / mappings / usermodel / address.hbm.xml 线程&#34; main&#34;中的例外情况java.lang.ExceptionInInitializerError 在Test.main(Test.java:19) 引起:org.hibernate.MappingException:读取资源时出错:com / ds / supercar / resources / mappings / usermodel / address.hbm.xml 在org.hibernate.cfg.Configuration.addResource(Configuration.java:449) 在org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1313) 在org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1285) 在org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1267) 在org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1234) 在org.hibernate.cfg.Configuration.configure(Configuration.java:1162) 在org.hibernate.cfg.Configuration.configure(Configuration.java:1148) 在Test.main(Test.java:12) 引起:org.hibernate.MappingException:必须指定标识符类型:com.ds.supercar.model.usermodel.Address 在org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:354) 在org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:293) 在org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:235) 在org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:151) 在org.hibernate.cfg.Configuration.add(Configuration.java:360) 在org.hibernate.cfg.Configuration.addInputStream(Configuration.java:397) 在org.hibernate.cfg.Configuration.addResource(Configuration.java:446) ......还有7个
请帮我解决这个问题:
答案 0 :(得分:1)
我认为您在映射文件中缺少ID中的name
。
从映射XML:<id name="emailId" column="email"/>