0

I am a beginner practicing hibernate ORM, I need help in resolving below Exception: Thank you

Entitiy:

package com.ds.supercar.model.usermodel;

public class Address {

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 file

<!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 true

Exception:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).

log4j:WARN Please initialize the log4j system properly. Initial SessionFactory creation Failed:org.hibernate.MappingException: Error reading resource: com/ds/supercar/resources/mappings/usermodel/address.hbm.xml Exception in thread "main" java.lang.ExceptionInInitializerError at Test.main(Test.java:19) Caused by: org.hibernate.MappingException: Error reading resource: com/ds/supercar/resources/mappings/usermodel/address.hbm.xml at org.hibernate.cfg.Configuration.addResource(Configuration.java:449) at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1313) at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1285) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1267) at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1234) at org.hibernate.cfg.Configuration.configure(Configuration.java:1162) at org.hibernate.cfg.Configuration.configure(Configuration.java:1148) at Test.main(Test.java:12) Caused by: org.hibernate.MappingException: must specify an identifier type: com.ds.supercar.model.usermodel.Address at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:354) at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:293) at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:235) at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:151) at org.hibernate.cfg.Configuration.add(Configuration.java:360) at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:397) at org.hibernate.cfg.Configuration.addResource(Configuration.java:446) ... 7 more

Please help me in resolving this problem:

2
  • Here is the remaining config XML file: <property name="hibernate.dialect">org.hibernate.dialect.Oracle11gDialect</property> <property name="show_sql">true</property> <mapping resource="com/ds/supercar/resources/mappings/usermodel/users.hbm.xml"/> <mapping resource="com/ds/supercar/resources/mappings/usermodel/address.hbm.xml"/> </session-factory> </hibernate-configuration> Commented Apr 22, 2016 at 19:45
  • Well, two things: 1. set data type in hbm file type="string", that's fine. 2. If you have an application-context, write the reference to your hbm file to be recognized. Commented Apr 26, 2016 at 22:33

1 Answer 1

1

I think you just are missing the name in your ID in the the mapping file.

From mapping XML:<id name="emailId" column="email"/>

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.