我已将使用SQL身份验证在Wildfly 9上运行的Web应用程序迁移到使用Windows身份验证。我还需要更新一个直接在数据库上执行某些维护任务的java实用程序。 Web应用程序工作正常,但实用程序似乎忽略了hibernate配置中的默认架构设置。跟踪SQL Server显示来自wildfly的查询有myschema.<table name>
,但来自我的实用程序的查询只有<table name>
。
在SQL Server上有一个登录(DOMAIN \ myservice)用于运行wildfly服务的域帐户,并且我将util作为同一帐户运行。
登录名映射到数据库中具有相同名称的用户(DOMAIN \ myservice)。
用户的默认架构为dbo。
util的-hibernate.cfg.xml中
<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>
战争的hibernate.cfg.xml
<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数据源
<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>
在我的实用程序的日志记录中,我看到:
SettingFactory:222 - Default schema: myschema
但是进一步下来我看到了错误:
com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name '<table name>'
表格在myschema中。
我尝试使用以下命令更新hibernate映射文件:
<hibernate-mapping schema="myschema">
<class name="MyType" table="table_name">
并且
<hibernate-mapping>
<class name="MyType" schema="myschema" table="table_name">
但这也不起作用。
事物的版本
答案 0 :(得分:1)
事实证明该实用程序正在使用我没有注意到的SQLQuery,似乎hibernate没有自动附加默认模式名称。