Hibernate连接sql server 2000 时,报错java.lang.AbstractMethodError

Exception in thread "main" java.lang.ExceptionInInitializerError
at com.wolf.execise.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:22)
at com.wolf.execise.util.HibernateUtil.<clinit>(HibernateUtil.java:10)
at com.wolf.execise.test.SessionTest.main(SessionTest.java:11)
Caused by: java.lang.AbstractMethodError: com.microsoft.jdbc.base.BaseDatabaseMetaData.getDatabaseMajorVersion()I
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:128)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
at com.wolf.execise.util.HibernateUtil.buildSessionFactory(HibernateUtil.java:16)
... 2 more

网上的解决办法:

java.lang.AbstractMethodError: com.microsoft.jdbc.base.BaseDatabaseMetaData.supportsGetGeneratedKeys()Z 

 

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" java.lang.AbstractMethodError: com.microsoft.jdbc.base.BaseDatabaseMetaData.supportsGetGeneratedKeys()Z
 at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:123)
 at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2119)
 at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2115)
 at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1339)
 at dao.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:31)
 at dao.BaseHibernateDAO.getSession(BaseHibernateDAO.java:13)
 at HibernateDAOTest.main(HibernateDAOTest.java:16)

 

解决:microsoft提供的数据库驱动存在bug。需要换一种驱动连接,使用jtds(下载地址:http://sourceforge.net/projects/jtds/files/)下载jtds1.2版,解压得到jtds-1.2.jar,引用到eclipse中项目目录下(去除原驱动引用),更改hibernate配置文件:

原驱动连接配置:

 <property name="connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
        <property name="connection.url">jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=hibernate</property>
更改jtds连接:   
        <property name="connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property>
        <property name="connection.url">jdbc:jtds:sqlserver://127.0.0.1:1433;DatabaseName=hibernate</property>

问题得到解决。补充:java代码调原驱动连接数据库是没有问题的,搭配hibernate会有此问题。


在连接mysql5.1时正常,连接sql2000时就是连不上,郁闷,终于在网上找到了解答,原来是sql驱动和hibernate的兼容性问题,现问题已解决,留此文备查.


 




郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。