简体   繁体   English

无法使用MS SQL 2016连接到Hibernate

[英]Unable to connect to Hibernate using MS SQL 2016

I'm trying launch my project configuration within Eclipse using Hibernate but keep running into this error: 我正在尝试使用Hibernate在Eclipse中启动我的项目配置,但一直遇到此错误:

    org.hibernate.console.HibernateConsoleRuntimeException: Could not load AnnotationConfiguration
Could not load AnnotationConfiguration
org.hibernate.console.HibernateConsoleRuntimeException: Could not load AnnotationConfiguration
Could not load AnnotationConfiguration
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [com.microsoft.sqlserver.jdbc.SQLServerDriver]
Unable to load class [com.microsoft.sqlserver.jdbc.SQLServerDriver]
java.lang.ClassNotFoundException: Could not load requested class : com.microsoft.sqlserver.jdbc.SQLServerDriver
Could not load requested class : com.microsoft.sqlserver.jdbc.SQLServerDriver

My Hibernate Config file: 我的Hibernate Config文件:

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM 
    "classpath://org/hibernate/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">
            com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
        <property name="connection.url">jdbc:microsoft:sqlserver://localhost:1234/databaseName=EX</property>
        <property name="connection.pool_size">10</property>
        <property name="hibernate.connection.username">EX</property>
        <property name="hibernate.connection.password">Test</property>
        <property name="hibernate.default_catalog">EX</property>
        <property name="hibernate.default_schema">dbo</property>
        <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
    </session-factory>
</hibernate-configuration>

Also, here is my pom.xml file: 另外,这是我的pom.xml文件:

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
                             http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!-- NOTE: This is an incomplete pom. It is here to define dependencies. 
        The project uses Apache Ant to build and deploy. -->
    <groupId>test.org</groupId>
    <artifactId>mExample</artifactId>
    <name>Mobile-Friendly Example Application</name>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <!-- <packaging>war</packaging> -->
    <properties>
        <java-version>1.8</java-version>
        <org.springframework-version>5.0.4.RELEASE</org.springframework-version>
        <org.aspectj-version>1.7.4</org.aspectj-version>
        <!-- NOTE: do not use Hibernate 5.2.x: broken JTA transaction management -->
        <hibernate.version>5.1.13.Final</hibernate.version>
        <hibernate.validator>5.4.1.Final</hibernate.validator>
        <c3p0.version>0.9.5.2</c3p0.version>
        <jackson.version>2.9.4</jackson.version>
        <project.buildDeploymentPath>C:/usr/local/jboss/standalone/deployments/</project.buildDeploymentPath>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <!--
        <dependency>
            <groupId>test.org.common</groupId>
            <artifactId>adt-common</artifactId>
            <version>1.10</version>
        </dependency>
        -->


        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${org.springframework-version}</version>
        </dependency>

        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.common</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>5.0.2.Final</version>
        </dependency>

        <!-- Hibernate Validator -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate.validator}</version>
        </dependency>

        <!-- JSTL -->
        <dependency>
            <groupId>org.apache.taglibs</groupId>
            <artifactId>taglibs-standard-impl</artifactId>
            <version>1.2.5</version>
        </dependency>

        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>${org.aspectj-version}</version>
        </dependency>

        <!-- Faster XML -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>

        <!-- @Inject -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <!-- Dependencies provided by WildFly A/S -->
        <dependency>
            <groupId>antlr</groupId>
            <artifactId>antlr</artifactId>
            <version>2.7.7</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.8.3</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.jtds</groupId>
            <artifactId>jtds</artifactId>
            <version>1.3.1</version>
            <scope>provided</scope>
        </dependency>

        <!-- scope compile = test + provided -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
            <scope>compile</scope>
        </dependency>

        <!-- Dependencies for unit tests -->
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk15on</artifactId>
            <version>1.57</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.10</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <artifactId>hamcrest-core</artifactId>
                    <groupId>org.hamcrest</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-library -->
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>1.9.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>3.2.3.RELEASE</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <!-- <build> <plugins> <plugin> <artifactId>maven-eclipse-plugin</artifactId> 
        <version>2.9</version> <configuration> <additionalProjectnatures> <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature> 
        </additionalProjectnatures> <additionalBuildcommands> <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand> 
        </additionalBuildcommands> <downloadSources>true</downloadSources> <downloadJavadocs>true</downloadJavadocs> 
        </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-compiler-plugin</artifactId> <version>2.5.1</version> <configuration> 
        <source>${java-version}</source> <target>${java-version}</target> <compilerArgument>-Xlint:all</compilerArgument> 
        </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> 
        <artifactId>exec-maven-plugin</artifactId> <version>1.2.1</version> <configuration> 
        <mainClass>org.test.int1.Main</mainClass> </configuration> </plugin> <plugin> 
        <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> 
        <configuration> <outputDirectory>${project.buildDeploymentPath}</outputDirectory> 
        </configuration> </plugin> </plugins> <finalName>${project.artifactId}</finalName> 
        </build> -->
</project>

Keep getting repeat 'Could not load AnnotationConfiguration' error. 不断重复出现“无法加载AnnotationConfiguration”错误。 I have tried everything and have exhausted every resource known possible, so any help or guidance is greatly appreciated! 我已经尝试了一切,并且用尽了所有可能的已知资源,因此,非常感谢您的帮助或指导!

I don't see a jdbc driver in the dependencies. 我在依赖项中没有看到jdbc驱动程序。 For example: 例如:

<dependency>
    <groupId>com.microsoft.sqlserver</groupId>
    <artifactId>mssql-jdbc</artifactId>
    <version>7.0.0.jre10</version>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM