0

I have made a connection to a mssql using persistence.xml in java. For doing that i had to copy sqljdbc_auth.dll in to system32 because i wanted to use the windows authentication in order to connect. Is there a way to achieve the same result without copying the dll file? Removing the dll causes this warning and prevents the execution:

Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path

This is my persistence:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="migration">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>migration.xcs.model.Kennzahl</class>
    <properties>
        <property name="javax.persistence.jdbc.driver"
            value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
        <property name="hibernate.dialect"  value="org.hibernate.dialect.SQLServerDialect" />
        <property name="javax.persistence.jdbc.url"
            value="jdbc:sqlserver://localhost:1433;databaseName=kendb;integratedSecurity=true;" />
        <property name="hibernate.archive.autodetection" value="class" />

    </properties>
</persistence-unit>

And these are my pom dependencies:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.0.5.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.0.5.Final</version>
    </dependency>
    <dependency>
        <groupId>com.microsoft.sqlserver</groupId>
        <artifactId>sqljdbc4</artifactId>
        <version>4.0</version>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>
Iman
  • 769
  • 1
  • 13
  • 51

1 Answers1

2

You have not added the path where sqljdbc_auth.dll is present.
Find out in the system where the DLL is and add that to your classpath.

Or in your Eclipse you can Run Configuration like this:

 -Djava.library.path=C:\path of the dll\
Abdelhak
  • 8,299
  • 4
  • 22
  • 36
  • yes, and that is my question. is there a way to use the windows authentication without adding the sqljdbc_auth.dll to system32. Something like using a specific property for authentication mode in persistence? If i copy sqljdbc_auth.dll to system32 it works, but i was just wondering if there were another way. – Iman Jan 05 '16 at 14:37
  • No there is no other optimization you can do, what Adbelhak suggests - correct. You can check this [related](http://stackoverflow.com/questions/17277001/dll-missing-in-jdbc) question as well. – javapapo Jan 05 '16 at 15:28