当前位置: 首页 > 面试题库 >

如何使用休眠配置Jaybird

何向荣
2023-03-14
问题内容

我将jaybird 2.2.3和hibernate 3.5一起使用,当我使用向导hibernate映射文件和pojos数据库时,出现以下错误“
java.lang.NullPointerException”

我在mysql上使用了相同的映射,并且可以正常工作,所以我相信这是jaybird中的问题

My 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.FirebirdDialect</property>
<property name="hibernate.connection.driver_class">org.firebirdsql.jdbc.FBDriver</property>
<property name="hibernate.connection.url">jdbc:firebirdsql://XXXXXX:XXXX/X:\XXXX\XXXX\XXX\XXX\XX\XXX.FDB</property>
<property name="hibernate.connection.username">sysdba</property>
<property name="hibernate.connection.password">XXXXX</property>
  </session-factory>
</hibernate-configuration>

编辑:

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:\Documents and  Settings\micro-40\workspace\testefirebird\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(Hibernat    eCodeGenWizardDescriptor.java:282)
[catch] at    org.netbeans.modules.hibernate.wizards.HibernateCodeGenWizardDescriptor.isValid(HibernateCod    eGenWizardDescriptor.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.access$200(WizardDescriptor.java:90)
    at org.openide.WizardDescriptor$Listener.stateChanged(WizardDescriptor.java:2094)
    at org.openide.util.WeakListenerImpl$Change.stateChanged(WeakListenerImpl.java:329)
    at org.openide.loaders.TemplateWizardIterImpl.run(TemplateWizardIterImpl.java:275)
    at org.openide.util.Mutex.doEvent(Mutex.java:1343)
    at org.openide.util.Mutex.writeAccess(Mutex.java:457)
    at     org.openide.loaders.TemplateWizardIterImpl.fireStateChanged(TemplateWizardIterImpl.java:261)
    at     org.openide.loaders.TemplateWizardIterImpl.setIterator(TemplateWizardIterImpl.java:120)
    at     org.openide.loaders.TemplateWizardIteratorWrapper.setIterator(TemplateWizardIteratorWrapper.    java:79)
    at org.openide.loaders.TemplateWizard.setTemplateImpl(TemplateWizard.java:209)
    at org.openide.loaders.TemplateWizard$1.run(TemplateWizard.java:231)
    at org.openide.loaders.TemplateWizard$1.run(TemplateWizard.java:228)
    at org.openide.util.Mutex.doEventAccess(Mutex.java:1363)
    at org.openide.util.Mutex.readAccess(Mutex.java:273)
at org.openide.loaders.TemplateWizard.setTemplate(TemplateWizard.java:228)
    at org.netbeans.modules.project.ui.TemplateChooserPanel.storeSettings(TemplateChooserPanel.java    :168)
    at     org.netbeans.modules.project.ui.TemplateChooserPanel.storeSettings(TemplateChooserPanel.java     :71)
    at org.openide.WizardDescriptor.storeSettingsAndNotify(WizardDescriptor.java:1379)
    at org.openide.WizardDescriptor.access$1700(WizardDescriptor.java:90)
    at org.openide.WizardDescriptor$Listener$1.run(WizardDescriptor.java:2117)
    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.GeneratedMethodAccessor182.invoke(Unknown Source)
    at    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.openide.util.WeakListenerImpl$ProxyListener.invoke(WeakListenerImpl.java:457)
    at com.sun.proxy.$Proxy57.actionPerformed(Unknown Source)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at   javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6505)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6270)
    at java.awt.Container.processEvent(Container.java:2229)
    at java.awt.Component.dispatchEventImpl(Component.java:4861)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4687)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
    at java.awt.Container.dispatchEventImpl(Container.java:2273)
    at java.awt.Window.dispatchEventImpl(Window.java:2719)
    at java.awt.Component.dispatchEvent(Component.java:4687)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
    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.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:702)
    at java.awt.EventQueue$4.run(EventQueue.java:700)
    at java.security.AccessController.doPrivileged(Native Method)
    at    java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
    at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
    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: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: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(DialogDisplayerI    mpl.java:260)
    at   org.netbeans.core.windows.services.DialogDisplayerImpl$1AWTQuery.run(DialogDisplayerImpl.jav    a: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:159)
    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)

有人能帮我吗?


问题答案:

在深入研究了Netbeans的代码并向Jaybird添加了额外的日志记录之后,问题在于Netbeans使用不返回资源的自定义类加载器加载驱动程序META- INF/services(特别是对于Jaybird 2.2.x :)META- INF/services/org.firebirdsql.gds.impl.GDSFactoryPlugin

这些服务定义用于加载可用的GDSFactoryPlugin定义(例如,用于类型4默认实现,类型4 Open
Office实现,类型2嵌入式客户端和类型2本机客户端)的驱动程序,这会中断驱动程序。

我将添加某种后备机制或将此插件定义移至单独的位置,并研究Netbeans为何这样做,因为这对我而言没有多大意义。

使用Jaybird 2.2.4或更高版本。

解决方法

注意 :不要使用此替代方法,它已被Jaybird 2.2.4的发布所取代

解决方法是我发布了Jaybird 2.2.4的快照版本,您可以从
http://sourceforge.net/projects/firebird/files/firebird-jca-jdbc-
driver/2.2.4-SNAPSHOT/
下载它(如果确定以今天(9月21日)作为构建日期,则某些sourceforge镜像仍可能会分发先前的快照)。

可以在Jaybird跟踪器中找到完整的2.2.4更改列表:版本2.2.4。



 类似资料:
  • Hibernate需要提前知道 - 在哪里可以找到定义Java类与数据库表相关的映射信息。 Hibernate还需要一组与数据库和其他相关参数相关的配置设置。 所有这些信息通常作为标准的Java属性文件hibernate.properties ,或者作为名为hibernate.cfg.xml的XML文件提供。 我将考虑XML格式的文件hibernate.cfg.xml来指定我的示例中所需的Hibe

  • 问题内容: 这是hibernate.cfg.xml中的内容 另外,我正在动态覆盖某些属性… 但是,当我运行它时,出现此错误… 如何配置属性,以便heroku找到postgres驱动程序? (我是hibernate和Heroku的新手,因此非常感谢您的帮助:) 问题答案: 来自Heroku Postgres的URL格式不是JDBC格式。它是一种多语言格式,因此所有平台都可以使用它。因此,您需要将UR

  • 问题内容: 这是MySQL的配置文件: 为SQL Server 2005指定什么?我这样做是这样的: 我的问题更确切地说是如何指定必须连接的数据库? 在MySQL中,我曾经这样做: 问题答案: 特定于数据库的 属性是: :JDBC驱动程序类 :JDBC URL :数据库用户 :数据库密码 :Hibernate的类名称,它允许Hibernate生成针对特定关系数据库优化的SQL。 要更改数据库,您必

  • 问题内容: 我不断得到: HibernateException:未配置CurrentSessionContext! 在我的代码中。其他返回的唯一信息是罪魁祸首是: 在我的hibernate.cfg.xml中。我的hibernate.cfg.xml文件中确实有该文件,并且我正在Tomcat 6中运行它。有人知道其他可能的原因吗? 问题答案: 我相信您需要将current_session_contex

  • 问题内容: 我试图配置文件为我和应用。相关部分如下所示: 但是,如果我不将库直接包含到我的buildpath中,我会不断获取。我有什么问题吗,因为在构建项目时不会下载此依赖项? 问题答案: 尝试代替。 这将包括所有必需的依赖项。进行此更改后,请检查Maven依赖项层次结构。 顺便说一句,Maven Central中最新的hibernate版本是4.1.18。

  • 问题内容: 我已经在Glassfish中使用jndi资源设置了一个连接池,并对其进行了设置。我很困惑如何配置hibernate以获取它。 我遇到了很多文章,将其配置为使用C3P0连接池。好吧,我迷路了。我发现我需要设置: 数据源是否与连接池中的数据源相同? hibernate.jndi.class是什么? hibernate.connection.username和hibernate.connec