Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Schema name not "quoted" for SQLServer in generated SQL
PostPosted: Thu Sep 01, 2016 4:10 pm 
Newbie

Joined: Mon Jul 02, 2007 1:04 pm
Posts: 3
I've done a fair bit of searching and experimentation on this and haven't had much luck. Apologies in advance if I've missed something obvious here.

hibernate-jpa-2.0-api - 1.0.1.Final-redhat-3
hibernate-core - 4.2.18.Final-redhat-2

We have a CI build that uses the git branch path to set the schema name and while that could be changed, I think this question is still relevant.

Code:
<property name="hibernate.default_schema" value="ci_jenkins_origin/jpa-integration-tests-get-them-working"/>


When Hibernate initializes, there are zero complaints about the schema. However, when SQL is generated (I'm using a criteria query as well as a simple em.find()) I get the following:

Hibernate SQL debug output:
Code:
Hibernate:
    select
        ....
    from
        ci_jenkins_origin/jpa-integration-tests-get-them-working.RELATION relation0_
.....
18:16:10,635 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions()] (SqlExceptionHelper.java:144) SQL Error: 102, SQLState: 42000
18:16:10,636 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions()] (SqlExceptionHelper.java:146) Incorrect syntax near '/'.


I checked in the SQLServerDialect code and see this:

Code:
   @Override
    public char closeQuote() {
      return ']';
   }

   @Override
    public char openQuote() {
      return '[';
   }


And I found code like this:

org.hibernate.internal.util
Code:
   public static boolean isQuoted(String name, Dialect dialect) {
      return name != null && name.length() != 0
            && ( ( name.charAt( 0 ) == '`' && name.charAt( name.length() - 1 ) == '`' )
                  || ( name.charAt( 0 ) == '"' && name.charAt( name.length() - 1 ) == '"' )
                  || ( name.charAt( 0 ) == dialect.openQuote()
                        && name.charAt( name.length() - 1 ) == dialect.closeQuote() ) );
   }


Which suggests that a backtick should be used. I tried that in the schema name property and it doesn't seem to work. I think it DOES work when you specify the schema name on a @Table annotation tho... I didn't trace the code enough to try to find out if it's used for SQL generation.

In fact, when I do use the backticks in the schema config property, I get an error on init:

Code:
Caused by: org.hibernate.MappingException: Unable to find column with logical name: GRP_OWNER_KID in org.hibernate.mapping.Table(GROUP_MEMBERSHIP) and its related supertables and secondary tables
   at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:582)
   ... 57 more


Thanks in advance for any help!

-Troy


Last edited by tkelley353 on Fri Sep 02, 2016 6:41 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Schema name not "quoted" for SQLServer in generated SQL
PostPosted: Fri Sep 02, 2016 12:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1103
Does this "ci_jenkins_origin/jpa-integration-tests-get-them-working" come from a default_schema setting?

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Schema name not "quoted" for SQLServer in generated SQL
PostPosted: Fri Sep 02, 2016 6:41 am 
Newbie

Joined: Mon Jul 02, 2007 1:04 pm
Posts: 3
Yes, I updated the original post to include that - I meant to include that detail...


Top
 Profile  
 
 Post subject: Re: Schema name not "quoted" for SQLServer in generated SQL
PostPosted: Sat Sep 03, 2016 5:31 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1103
You need to set both the schema and the catalog:

Code:
<property name="hibernate.default_catalog" value="ci_jenkins_origin"/>
<property name="hibernate.default_schema" value="jpa-integration-tests-get-them-working"/>

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.