Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSSQL schema & Hibernate 5.1.0.Final (table not found)

I'm trying to understand how to configure my Hibernate to work properly with my MSSQL DB and its schemas.

The problem is that during validation of tables, it logs (for every table):

org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl
- HHH000262: Table not found SHARED_CONFIGURATION

I debugged Hibernate to find out what causes this and found that it calls something like:

EXECUTE [mydb]..sp_columns N'SHARED_CONFIGURATION',N'',N'mydb'

Notice that 2nd parameter is schema name and there is passed empty string. When I tried to run this query against DB it returned empty result set. But when I passed 'dbo' as 2nd parameter the result set was not empty (meaning that Hibernate should call this instead).

OK so I was like it seems that I need to define schema. But both setting hibernate.default_schema or setting schema in @Table annotation on my entites threw exception:

Schema-validation: missing table [SHARED_CONFIGURATION]

So now I'm wondering what is the real problem. I also wanted to set default schema in my DB but was not allowed (Cannot alter the user 'sa', because it does not exist or you do not have permission.) even when executed with user 'sa' itself:

ALTER USER sa WITH DEFAULT_SCHEMA = dbo;

Note that this happens with any driver (JTDS, official MS driver..) Can someone explain what is happening here and how "correctly" get rid of that warning message in log that says table does not exist even when it exists (and application is able to run properly with the database)?

like image 305
zdenda.online Avatar asked Nov 09 '22 14:11

zdenda.online


1 Answers

I had the same problem and solved by setting the property hibernate.hbm2ddl.jdbc_metadata_extraction_strategy to individually

like image 157
Manza Avatar answered Nov 14 '22 23:11

Manza