1

I am getting this below Exception.am using Struts2 and Hibernate for developing web application.can any one help me to resolve this Issue ?

org.hibernate.MappingException: Unknown entity: Pojo.USER [Packagename.entityClassname]


Hibernate.cfg.xml file Content :-

<?xml version="1.0" encoding="UTF-8"?>
<!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="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/databasename
</property>
<property name="connection.username">root</property>
<property name="connection.password">admin</property>
<property name="cache.provider_class">
org.hibernate.cache.HashtableCacheProvider</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">false</property>
</session-factory>
</hibernate-configuration>

USER's Entity Class content :-

package Pojo;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="user")
public class USER {

    @Id
    @GeneratedValue
    @Column(name="USER_ID")
    private int id;

    @Column(name="USER_NAME")
    private String name;

    @Column(name="USER_PASSWORD")
    private String password;

    @Column(name="USER_GENDER")
    private String gender;

    @Column(name="USER_COUNTRY")
    private String country; 

    @Column(name="USER_ABOUT_YOU")
    private String aboutyou;

    @Column(name="USER_MAILING_LIST")
    private boolean mailinglist;

    public int getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

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

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getAboutyou() {
        return aboutyou;
    }

    public void setAboutyou(String aboutyou) {
        this.aboutyou = aboutyou;
    }

    public boolean isMailinglist() {
        return mailinglist;
    }

    public void setMailinglist(boolean mailinglist) {
        this.mailinglist = mailinglist;
    }

}
1
  • Declare mapping file in hibernate.cfg ... <mapping class="Pojo.User"> Commented Apr 22, 2015 at 10:15

2 Answers 2

1
<?xml version="1.0" encoding="UTF-8"?>
<!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="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/databasename
</property>
<property name="connection.username">root</property>
<property name="connection.password">admin</property>
<property name="cache.provider_class">
org.hibernate.cache.HashtableCacheProvider</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">false</property>
<mapping class="Pojo.User">
</session-factory>

</hibernate-configuration>

Use mapping class,so that hibernate will come to know your entity class--> <mapping class="Pojo.User">

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

Comments

1

USER entity is unknown to your Hibernate session. Add <mapping class="Pojo.USER"/> in session-factory configuration.

    ...
    <property name="current_session_context_class">thread</property>
    <property name="hibernate.show_sql">false</property>
    <mapping class="Pojo.USER"/>
</session-factory>
</hibernate-configuration>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.