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