-1

this is my exception

Caused by: java.lang.NullPointerException
    at org.hibernate.mapping.Table.setName(Table.java:181)
    at org.hibernate.cfg.Configuration$MappingsImpl.addTable(Configuration.java:2937)
    at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:344)
    at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:327)
    at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:178)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXml(Configuration.java:3816)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processHbmXmlQueue(Configuration.java:3808)
    at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3796)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1412)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)
    at sessionfactoryconfig.HibernateUtil.<clinit>(HibernateUtil.java:13)
    ... 31 more

this is my hibernate.cfg.xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="connection.url">jdbc:mysql://127.0.0.1:3306/university</property>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="connection.username">root</property>
        <property name="connection.password">root</property>
        <property name="hbm2ddl.auto">update</property>
        <property name="connection.pool_size">10</property>
        <property name="show_sql">true</property>

        <mapping resource="mappingfiles/student.hbm.xml" />
    </session-factory>
</hibernate-configuration>

and this is my mapping file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="mappingfiles">
    <class name="" table="" schema="university">
        <id name="id" column="id">
            <generator class="native"/>
        </id>
        <property name="name" column="name" />
        <property name="address" column="address" />
        <property name="mobile" column="mobile" />    
    </class>
</hibernate-mapping>

and this is my modal class

package modal;

public class Student {
    private int id;
    private String name;
    private String address;
    private String mobile;

    public Student() {
    }

    public Student(int id, String name, String address, String mobile) {
        this.id = id;
        this.name = name;
        this.address = address;
        this.mobile = mobile;
    }

    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 getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }
}

Screenshot

please help me in this project it has very little mistake, i have created DAO also but right now i am not using any DAO. i am doing it just in a simple manner first. I am using hibernate version 4.3.11. please help.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Aniket
  • 23
  • 1
  • 8
  • can you please post exception stack trace? – Praveen Kumar K S Apr 09 '16 at 11:34
  • now i have edit it – Aniket Apr 09 '16 at 12:04
  • `class name="" table=""`: what do you think that should do? WHy are you still using ugly xml files to define your mapping instead of using standard JPA annotations? – JB Nizet Apr 09 '16 at 12:05
  • is there any alternative to this......i mean without xml configuration?? – Aniket Apr 09 '16 at 12:19
  • Err, yes: standard JPA annotations. Read the user guide. – JB Nizet Apr 09 '16 at 12:20
  • this is the new error now Severe: Session factory creation failedorg.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set Warning: StandardWrapperValve[REGISTER_STUDENT]: Servlet.service() for servlet REGISTER_STUDENT threw exception java.lang.ExceptionInInitializerError at sessionfactoryconfig.HibernateUtil.(HibernateUtil.java:19) at controllers.RegistrationServlet.doPost(RegistrationServlet.java:29) – Aniket Apr 09 '16 at 12:32
  • Does this answer your question? [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – TylerH Sep 08 '22 at 13:51

1 Answers1

1

Provide values for name and table attributes. Hibernate mapping configuration is invalid.

<class name="" table="" schema="university">

You've got this error since there is no name specified.

Caused by: java.lang.NullPointerException
    at org.hibernate.mapping.Table.setName(Table.java:181)

EDIT: I think you should change to

 <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
Keerthivasan
  • 12,760
  • 2
  • 32
  • 53
  • Did you provide both class name and table name? Check out all the mapping files.. – Keerthivasan Apr 09 '16 at 12:17
  • Severe: Session factory creation failedorg.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set Warning: StandardWrapperValve[REGISTER_STUDENT]: Servlet.service() for servlet REGISTER_STUDENT threw exception java.lang.ExceptionInInitializerError at sessionfactoryconfig.HibernateUtil.(HibernateUtil.java:19) at controllers.RegistrationServlet.doPost(RegistrationServlet.java:29) this is now..... – Aniket Apr 09 '16 at 12:23
  • I think you will have to prepend with `hibernate.dialect` in your cfg file. Please check this link for reference - http://www.tutorialspoint.com/hibernate/hibernate_configuration.htm – Keerthivasan Apr 09 '16 at 12:35
  • dear friend look into my code i have done this already first from the start.... but it can not find that. – Aniket Apr 09 '16 at 12:41
  • The property `hibernate.dialect` is one of the most important property that should be provided to hibernate. you should also check if the configuration file is loaded in the classpath. – Keerthivasan Apr 09 '16 at 12:47