jpa 连SQL2000数据库报错

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'RecordDAO': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in ServletContext resource [/WEB-INF/spring.xml]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError: com.microsoft.jdbc.base.BaseDatabaseMetaData.supportsGetGeneratedKeys()Z
	at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessPropertyValues(PersistenceAnnotationBeanPostProcessor.java:341)


得知是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=portal</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=portal</property>

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


你可能感兴趣的:(java,Hibernate,jdbc,Microsoft,jpa)