2013-05-17 104 views
1

我剛剛在我的電腦上重新安裝了所有東西,不得不重新安裝Netbeans。 我打開了一個hibernate項目,我剛剛向數據庫中添加了3個新表。 我試圖通過使用「Hibernate映射文件和POJO從數據庫」映射這些文件。 不過,NetBeans給了我以下錯誤:用netbeans從數據庫生成Hibernate映射文件和POJO

INFO [org.netbeans.modules.hibernate.wizards.HibernateCodeGenWizardDescriptor]: access to hibernate fails. 
org.hibernate.HibernateException: could not instantiate QueryTranslatorFactory: org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory 
    at org.hibernate.cfg.SettingsFactory.createQueryTranslatorFactory(SettingsFactory.java:391) 
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:222) 
    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) 
    at org.netbeans.modules.hibernate.wizards.HibernateCodeGenWizardDescriptor.isValid(HibernateCodeGenWizardDescriptor.java:177) 
    at org.openide.WizardDescriptor.updateStateOpen(WizardDescriptor.java:872) 
    at org.openide.WizardDescriptor.updateState(WizardDescriptor.java:820) 
    at org.openide.loaders.TemplateWizard.updateState(TemplateWizard.java:754) 
    at org.netbeans.modules.project.ui.NewFileWizard.updateState(NewFileWizard.java:124) 
    at org.openide.WizardDescriptor._updateState(WizardDescriptor.java:798) 
    at org.openide.WizardDescriptor.goToNextStep(WizardDescriptor.java:1070) 
    at org.openide.WizardDescriptor.access$1800(WizardDescriptor.java:90) 
    at org.openide.WizardDescriptor$Listener$1.run(WizardDescriptor.java:2122) 
    at org.openide.WizardDescriptor.lazyValidate(WizardDescriptor.java:1502) 
    at org.openide.WizardDescriptor.access$1900(WizardDescriptor.java:90) 
    at org.openide.WizardDescriptor$Listener.actionPerformed(WizardDescriptor.java:2141) 
    at sun.reflect.GeneratedMethodAccessor231.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.openide.util.WeakListenerImpl$ProxyListener.invoke(WeakListenerImpl.java:457) 
    at com.sun.proxy.$Proxy43.actionPerformed(Unknown Source) 
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) 
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) 
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) 
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) 
    at javax.swing.AbstractButton.doClick(AbstractButton.java:357) 
    at javax.swing.AbstractButton.doClick(AbstractButton.java:337) 
    at org.openide.WizardDescriptor.doNextClick(WizardDescriptor.java:1618) 
    at org.netbeans.modules.project.ui.TemplateChooserPanel$1.actionPerformed(TemplateChooserPanel.java:95) 
    at org.netbeans.modules.project.ui.TemplateChooserPanelGUI$FileChooserBuilder.actionPerformed(TemplateChooserPanelGUI.java:418) 
    at org.openide.explorer.view.ListView.performObjectAt(ListView.java:684) 
    at org.openide.explorer.view.ListView$PopupSupport.mouseClicked(ListView.java:1327) 
    at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:253) 
    at java.awt.Component.processMouseEvent(Component.java:6300) 
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3275) 
    at java.awt.Component.processEvent(Component.java:6062) 
    at java.awt.Container.processEvent(Container.java:2039) 
    at java.awt.Component.dispatchEventImpl(Component.java:4660) 
    at java.awt.Container.dispatchEventImpl(Container.java:2097) 
    at java.awt.Component.dispatchEvent(Component.java:4488) 
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4575) 
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4245) 
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4166) 
    at java.awt.Container.dispatchEventImpl(Container.java:2083) 
    at java.awt.Window.dispatchEventImpl(Window.java:2489) 
    at java.awt.Component.dispatchEvent(Component.java:4488) 
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:674) 
    at java.awt.EventQueue.access$400(EventQueue.java:81) 
    at java.awt.EventQueue$2.run(EventQueue.java:633) 
    at java.awt.EventQueue$2.run(EventQueue.java:631) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) 
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:98) 
    at java.awt.EventQueue$3.run(EventQueue.java:647) 
    at java.awt.EventQueue$3.run(EventQueue.java:645) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) 
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:644) 
    at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:178) 
    at java.awt.Dialog$1.run(Dialog.java:1052) 
    at java.awt.Dialog$3.run(Dialog.java:1104) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.awt.Dialog.show(Dialog.java:1102) 
    at org.netbeans.core.windows.services.NbPresenter.superShow(NbPresenter.java:1076) 
    at org.netbeans.core.windows.services.NbPresenter.doShow(NbPresenter.java:1126) 
    at org.netbeans.core.windows.services.NbPresenter.run(NbPresenter.java:1098) 
    at org.netbeans.core.windows.services.NbPresenter.run(NbPresenter.java:128) 
    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:1083) 
    at java.awt.Component.show(Component.java:1591) 
    at java.awt.Component.setVisible(Component.java:1543) 
    at java.awt.Window.setVisible(Window.java:843) 
    at java.awt.Dialog.setVisible(Dialog.java:987) 
    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:209) 
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:672) 
    at java.awt.EventQueue.access$400(EventQueue.java:81) 
    at java.awt.EventQueue$2.run(EventQueue.java:633) 
    at java.awt.EventQueue$2.run(EventQueue.java:631) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87) 
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:642) 
    at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159) 
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) 
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) 
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) 
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) 
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) 
Caused by: java.lang.ClassCastException: org.hibernate.hql.internal.classic.ClassicQueryTranslatorFactory cannot be cast to org.hibernate.hql.QueryTranslatorFactory 
    at org.hibernate.cfg.SettingsFactory.createQueryTranslatorFactory(SettingsFactory.java:388) 
    ... 94 more 

我hibernate.cfg文件如下所示:

<?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.microsoft.sqlserver.jdbc.SQLServerDriver</property> 
    <property name="hibernate.connection.url">jdbc:sqlserver://SERVER:PORT;databaseName=NAME</property> 
    <property name="hibernate.connection.username">USER</property> 
    <property name="hibernate.connection.password">PASS</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.internal.classic.ClassicQueryTranslatorFactory</property> 
    <mapping resource="com/bmw/resources/LocationDept.hbm.xml"/> 
</session-factory> 
</hibernate-configuration> 

我連接到SQL Server 2008數據庫。

我使用Hibernate 4.2.0和在我的類路徑中的以下JAR:

antlr-2.7.7.jar 
dom4j-1.6.1.jar 
hibernate-commons-annotations-4.0.1.Final.jar 
hibernate-core-4.2.0.Final.jar 
hibernate-jpa-2.0-api-1.0.1.Final.jar 
javassist-3.15.0-GA.jar 
jboss-logging-3.1.0.GA.jar 
jboss-transaction-api_1.1_spec-1.0.0.Final.jar 
hibernate-entitymanager-4.2.0.Final.jar 
sqljdbc4.jar 
log4j-1.2.17.jar 

任何想法?

回答

1

這是對我工作:

變化hibernate.query.factory_classorg.hibernate.hql.classic.ClassicQueryTranslatorFactory,然後去爲Hibernate Mapping Files and POJOs from Database

您正在使用改變它做回org.hibernate.hql.內部.classic.ClassicQueryTranslatorFactory

+0

同樣的後發生在我身上。這似乎是我找到的唯一途徑。 +1 –

+0

謝謝!認爲它只對我有用。 – zlinks

相關問題