I have migrated a web application running on Wildfly 9 from using SQL authentication to using windows authentication. I also need to update a java utility that does some maintenance tasks directly on the database. The web application works fine, but the utility seems to ignore the default schema setting in the hibernate configuration. Tracing on the sql server shows the queries comming from wildfly have myschema.<table name> but the queryies from my utility have just <table name>.
There is a login (DOMAIN\myservice) on the SQL Server for the domain account that wildfly service runs under, and I run the util as the same account.
The login is mapped to a user on the database with the same name (DOMAIN\myservice).
The user has a default schema of dbo.
util-hibernate.cfg.xmlCode:
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServer2008Dialect</property>
<property name="hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:sqlserver://sqlhost\INSTANCE:1433;databaseName=MYAPP;integratedSecurity=true</property>
<property name="hibernate.connection.pool_size">5</property>
<property name="hibernate.default_schema">myschema</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="....hbm.xml"/>
<mapping resource="...hbm.xml"/>
...
</session-factory>
</hibernate-configuration>
war-hibernate.cfg.xmlCode:
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.datasource">jdbc/MYAPP</property>
<property name="hibernate.default_schema">myschema</property>
<mapping resource="....hbm.xml"/>
<mapping resource="...hbm.xml"/>
...
</session-factory>
</hibernate-configuration>
wildfly datasourceCode:
<datasource jndi-name="java:jdbc/MYAPP" pool-name="MyDataSource" enabled="true">
<connection-url>jdbc:sqlserver://sqlhost\INSTANCE;databaseName=MYAPP;integratedSecurity=true</connection-url>
<driver>sqljdbc4.jar</driver>
<pool>
<max-pool-size>10</max-pool-size>
</pool>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker" />
<validate-on-match>false</validate-on-match>
<background-validation>true</background-validation>
<background-validation-millis>30000</background-validation-millis>
</validation>
</datasource>
In the logging for my utility I see:
Code:
SettingFactory:222 - Default schema: myschema
But further down I see the error:
Code:
com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name '<table name>'
Where the table is in myschema.
I have tried updating hibernate mapping files with:
Code:
<hibernate-mapping schema="myschema">
<class name="MyType" table="table_name">
And
Code:
<hibernate-mapping>
<class name="MyType" schema="myschema" table="table_name">
But that didn't work either.
Versions of thingsWildfly 9.0.2.Final
Hibernate 3.5.6-Final
Microsoft SQL JDBC 4.1
SQL Server 2014
JRE 7u67