java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to rmc.entity.UserEntity
<p>I have created a Database Access Object (DAO) class, entity class, and table script, but I am getting an error that cannot be mapped to entity.<br>
I am using hibernate framework and the connections are made properly with the database but still error occurs. please check the code below and help in any ways you can, all the files are provided below.</p>

<p>Table Script</p>

<pre><code>DROP TABLE rmc_user;
CREATE TABLE rmc_user(
user_id VARCHAR(50) NOT NULL,
user_name VARCHAR(20) NOT NULL,
user_email VARCHAR(50) NOT NULL,
user_password VARCHAR(20),
CONSTRAINT rmc_user_user_id_pk PRIMARY KEY (user_id),
CONSTRAINT rmc_user_user_email_un UNIQUE (user_email) 
);

INSERT INTO rmc_user VALUES   ('101','yashik','yas@gmail.com','gulati123');

SELECT * FROM rmc_user;
</code></pre>

<p>DAO Class</p>

<pre><code>package rmc.dao;

import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import rmc.bean.User;
import rmc.entity.UserEntity;
import rmc.resources.HibernateUtility;

public class LoginDAOImpl implements LoginDAO {

    @SuppressWarnings("deprecation")
    public User getUserDetails(String userName, String password) {
        SessionFactory sessionFactory = HibernateUtility.createSessionFactory();
        Session session = null;
        User u1 = null;
        session = sessionFactory.openSession();
        session.beginTransaction();
        System.out.println("begin trx");
        Query q1 = session
                .createNativeQuery("select * from rmc_user where user_name=?");
        System.out.println("begin trx");
        q1.setParameter(0, userName);
        System.out.println("begin trx");
        @SuppressWarnings("unchecked")
        List&lt;UserEntity&gt; l1 = q1.list();
        System.out.println("begin trx");
        System.out.println("size is"+l1.size());
        if (l1.size() == 0) {
            System.out.println("no Such user Exist");
        } else if (!(l1.get(0).getPassword().equals(password))) {
            System.out.println("Invalid Password");
        }
        System.out.println("begin trx");
        u1 = new User();
        u1.setEmail(l1.get(0).getEmail());
        u1.setPassword(l1.get(0).getPassword());
        u1.setUserId(l1.get(0).getUserId());
        u1.setUserName(l1.get(0).getUserName());
        session.getTransaction().commit();
        if (session != null) {
            session.close();
        }
        return u1;
    }
}
</code></pre>

<p>Entity Class</p>

<pre><code>package rmc.entity;
@Id
@Column(name="user_id")
private String userId;
@Column(name="user_name")
private String userName;
@Column(name="user_email")
private String email;
@Column(name="user_password")
private String password;

//getter and setter 
}
</code></pre>

<p>Error Message</p>

<pre><code>Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to rmc.entity.UserEntity
at rmc.dao.LoginDAOImpl.getUserDetails(LoginDAOImpl.java:32)
at rmc.test.UserInterface.main(UserInterface.java:9)
</code></pre>

<p>UPDATED</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE hibernate-configuration SYSTEM 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"&gt;

&lt;hibernate-configuration&gt;
&lt;session-factory&gt;
    &lt;property name="hibernate.dialect"&gt;
        org.hibernate.dialect.MySQLDialect
    &lt;/property&gt;
    &lt;property name="hibernate.connection.driver_class"&gt;
        com.mysql.jdbc.Driver
    &lt;/property&gt;

    &lt;!-- Assume test is the database name --&gt;
    &lt;property name="hibernate.connection.url"&gt;
        jdbc:mysql://localhost:3306/rmc
    &lt;/property&gt;
    &lt;property name="hibernate.connection.username"&gt;
        ******
    &lt;/property&gt;
    &lt;property name="hibernate.connection.password"&gt;
        ******
    &lt;/property&gt;


    &lt;!-- List of XML mapping files --&gt;
    &lt;mapping class="rmc.entity.UserEntity"/&gt;

&lt;/session-factory&gt;
</code></pre>

<p></p>