我正在尝试按照一个简单的教程来使用休眠框架创建 Web 应用程序。
当我尝试添加 Hibernate 映射文件和 POJOs 文件时,Netbeans 给了我以下错误并且不允许我继续:
Hibernate 配置失败并显示消息:java.lang.NullPointerException 有关异常详细信息,请参阅 message.log。并且不允许我创建新文件。
我的 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.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/cats</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
</session-factory>
</hibernate-configuration>
我的hibernate.reveng.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
<schema-selection match-catalog="cats"/>
<table-filter match-name="user"/>
<table-filter match-name="cat"/>
</hibernate-reverse-engineering>
我的数据库名称是“cats”,它包含 2 个表:用户和猫。我与数据库的 jdbc 连接具有以下属性: 数据库 URL:jdbc:mysql://localhost:3306/cats?zeroDateTimeBehavior=convertToNull和驱动程序:com.mysql.jdbc.Driver
你能帮忙吗?谢谢!
编辑:这是我的 IDE 日志:
INFO [org.hibernate.cfg.Configuration]: configuring from file: hibernate.cfg.xml
INFO [org.hibernate.cfg.Configuration]: Configured SessionFactory: null
INFO [org.hibernate.cfg.reveng.OverrideRepository]: Override file: C:\Users\Rima\Documents\NetBeansProjects\MyCats\src\java\hibernate.reveng.xml
INFO [org.netbeans.modules.hibernate.util.HibernateUtil]: Found pre-existing database connection.
INFO [org.netbeans.modules.hibernate.util.HibernateUtil]: Database Connection is pre-established. Returning the conneciton.
INFO [org.hibernate.connection.ConnectionProviderFactory]: Initializing connection provider: org.netbeans.modules.hibernate.util.CustomJDBCConnectionProvider
INFO [org.netbeans.modules.hibernate.util.CustomJDBCConnectionProvider]: Loaded JDBC driver
INFO [org.netbeans.modules.hibernate.util.CustomJDBCConnectionProvider]: Got connection.. returning
INFO [org.netbeans.modules.hibernate.wizards.HibernateCodeGenWizardDescriptor]: access to hibernate fails.
java.lang.NullPointerException
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:86)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2005)
at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:40)
at org.netbeans.modules.hibernate.wizards.HibernateCodeGenWizardDescriptor.checkConfig(HibernateCodeGenWizardDescriptor.java:282)
[catch] at org.netbeans.modules.hibernate.wizards.HibernateCodeGenWizardDescriptor.isValid(HibernateCodeGenWizardDescriptor.java:177)
at org.openide.WizardDescriptor.updateStateOpen(WizardDescriptor.java:900)
at org.openide.WizardDescriptor.updateState(WizardDescriptor.java:844)
at org.openide.loaders.TemplateWizard.updateState(TemplateWizard.java:732)
at org.netbeans.modules.project.ui.NewFileWizard.updateState(NewFileWizard.java:122)
at org.openide.WizardDescriptor$Listener.stateChanged(WizardDescriptor.java:2094)
at org.openide.util.WeakListenerImpl$Change.stateChanged(WeakListenerImpl.java:329)
at org.openide.util.ChangeSupport.fireChange(ChangeSupport.java:133)
at org.openide.util.ChangeSupport.fireChange(ChangeSupport.java:119)
at org.netbeans.modules.project.ui.TemplateChooserPanel.stateChanged(TemplateChooserPanel.java:182)
at org.openide.util.ChangeSupport.fireChange(ChangeSupport.java:133)
at org.openide.util.ChangeSupport.fireChange(ChangeSupport.java:119)
at org.netbeans.modules.project.ui.TemplateChooserPanelGUI.fireChange(TemplateChooserPanelGUI.java:164)
at org.netbeans.modules.project.ui.TemplateChooserPanelGUI.access$500(TemplateChooserPanelGUI.java:78)
at org.netbeans.modules.project.ui.TemplateChooserPanelGUI$FileChooserBuilder.fireChange(TemplateChooserPanelGUI.java:380)
at org.netbeans.modules.project.ui.TemplatesPanelGUI.propertyChange(TemplatesPanelGUI.java:329)
at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)
at java.awt.Component.firePropertyChange(Component.java:8382)
at org.netbeans.modules.project.ui.TemplatesPanelGUI$ExplorerProviderPanel.access$900(TemplatesPanelGUI.java:460)
at org.netbeans.modules.project.ui.TemplatesPanelGUI$ExplorerProviderPanel$2.run(TemplatesPanelGUI.java:542)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:158)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:154)
at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:182)
at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:221)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:219)
at java.awt.Dialog.show(Dialog.java:1082)
at org.netbeans.core.windows.services.NbPresenter.superShow(NbPresenter.java:1074)
at org.netbeans.core.windows.services.NbPresenter.doShow(NbPresenter.java:1109)
at org.netbeans.core.windows.services.NbPresenter.run(NbPresenter.java:1096)
at org.netbeans.core.windows.services.NbPresenter.run(NbPresenter.java:126)
at org.openide.util.Mutex.doEventAccess(Mutex.java:1363)
at org.openide.util.Mutex.readAccess(Mutex.java:273)
at org.netbeans.core.windows.services.NbPresenter.show(NbPresenter.java:1081)
at java.awt.Component.show(Component.java:1651)
at java.awt.Component.setVisible(Component.java:1603)
at java.awt.Window.setVisible(Window.java:1014)
at java.awt.Dialog.setVisible(Dialog.java:1005)
at org.netbeans.core.windows.services.DialogDisplayerImpl$1AWTQuery.showDialog(DialogDisplayerImpl.java:260)
at org.netbeans.core.windows.services.DialogDisplayerImpl$1AWTQuery.run(DialogDisplayerImpl.java:186)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:727)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:688)
at java.awt.EventQueue$3.run(EventQueue.java:686)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:697)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:158)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)