0

das ist meine Ausnahmejava.lang.NullPointerException bei org.hibernate.mapping.Table.setName

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 

dies meine hibernate.cfg.xml Datei ist

<?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> 

und das ist mein Mapping Datei

<?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> 

und dies ist meine modale Klasse

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

Bitte helfen Sie mir in diesem Projekt ist es sehr wenig Fehler hat, ich habe auch erstellt DAO aber jetzt verwende ich keine DAO. Ich mache es zuerst einfach. Ich verwende Hibernate Version 4.3.11. bitte hilfe.

+0

ändern sollten Sie bitte Ausnahme-Stack-Trace schreiben? –

+0

jetzt habe ich es bearbeiten – Aniket

+0

'class name =" "table =" "': Was denkst du, dass sollte das tun? Warum verwenden Sie immer noch hässliche XML-Dateien, um Ihr Mapping zu definieren, anstatt JPA-Standardanmerkungen zu verwenden? –

Antwort

0

Geben Sie Werte für Namen und Tabellenattribute ein. Hibernate Mapping-Konfiguration ist ungültig.

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

Sie haben diesen Fehler, da kein Name angegeben ist.

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

EDIT: Ich glaube, Sie zu

<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
+0

Haben Sie sowohl Klassenname und Tabellenname angegeben? Überprüfen Sie alle Mapping-Dateien. – Keerthivasan

+0

Schwerwiegend: Session Factory-Erstellung failedorg.hibernate.HibernateException: Zugriff auf DialectResolutionInfo kann nicht null sein, wenn 'Hibernate.dialect' nicht festgelegt Warnung: StandardWrapperValve [REGISTER_STUDENT]: Servlet.service() für Servlet REGISTER_STUDENT hat Ausnahme java.lang.ExceptionInInitializerError \t bei sessionfactoryconfig.HibernateUtil ausgelöst. (HibernateUtil.java:19) \t bei controllers.RegistrationServlet.doPost (RegistrationServlet.java:29) Dies ist jetzt ..... – Aniket

+0

Ich denke, Sie müssen mit 'Hibernate.dialect' in Ihrer cfg-Datei voranzustellen. Bitte überprüfen Sie diesen Link als Referenz - http://www.tutorialspoint.com/hibernate/hibernate_configuration.htm – Keerthivasan

Verwandte Themen