gpt4 book ai didi

java - hibernate配置xml中的错误: Failed:org. hibernate.MappingException:读取资源时出错:com/

转载 作者:行者123 更新时间:2023-12-01 10:01:04 25 4
gpt4 key购买 nike

我是练习 hibernate ORM 的初学者,我需要帮助解决以下异常:谢谢

实体:

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 配置文件 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 真的

异常(exception):

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线程“main”中的异常 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 更多

请帮我解决这个问题:

最佳答案

我认为您只是错过了 name在映射文件中您的 ID 中。

来自映射 XML:<id name="emailId" column="email"/>

关于java - hibernate配置xml中的错误: Failed:org. hibernate.MappingException:读取资源时出错:com/,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36802025/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com