package common.ejdugedemo;
import org.hibernate.SessionFactory; import org.hibernate.cfg.AnnotationConfiguration;
public class HibernateUtil {
public static SessionFactory buildSessionFactory() throws ExceptionInInitializerError
{
return new AnnotationConfiguration().configure().buildSessionFactory();
}
}
***************** hibernate.cfg.xml中************************* *
<?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="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/eattorney?characterEncoding=utf8</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping class="common.hibernate.bean.Admin_answer"/>
<mapping class="common.hibernate.bean.Admin_question"/>
<mapping class="common.hibernate.bean.Audit_log"/>
<mapping class="common.hibernate.bean.Billing"/>
<mapping class="common.hibernate.bean.Custom_contract_billing_reports"/>
<mapping class="common.hibernate.bean.Dummyvariable"/>
<mapping class="common.hibernate.bean.Ejduge_login"/>
<mapping class="common.hibernate.bean.Entity_registration"/>
<mapping class="common.hibernate.bean.Gc_percentage"/>
<mapping class="common.hibernate.bean.Model_contract"/>
<mapping class="common.hibernate.bean.User_master"/>
<mapping class="common.hibernate.bean.User_registration"/>
<mapping class="common.hibernate.bean.Weightage"/>
<mapping class="common.hibernate.bean.Word_synonym"/>
<mapping class="common.hibernate.bean.Word_synonym_entity_wise"/>
<mapping class="common.hibernate.bean.Word_synonym_temp"/>
</session-factory>
</hibernate-configuration>
***********************构建会话工厂时出现异常****************
java.lang.NullPointerException at org.hibernate.util.StringHelper.qualify(StringHelper.java:264)at at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:196) 在 org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1127) 在 org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:296) 在 org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1283) 在 common.ejdugedemo.HibernateUtil.buildSessionFactory(HibernateUtil.java:10) 在org.apache.jsp.login_jsp._jspService(login_jsp.java:92)at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) 在 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) 在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:717)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 在 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) 在 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857) 在 org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:588) 在 org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:489) 在java.lang.Thread.run(Thread.java:619)
答案 0 :(得分:0)
com.mysql.jdbc.Driver
JDBC:MySQL的://本地主机:3306 / eattorney的characterEncoding = UTF8
根
根
真正
更新
org.hibernate.dialect.MySQLDialect