Hello,
i've got following issue. If i use @javax.persistence.MapKey with @JoinTable, the generated formula for MapKey doesn't contain the table schema/default-schema prefix. On the RDBMS which expect the schema name (mssql or postgresql) those selects don't work. I have investigated the problem and found the place within the method org.hibernate.cfg.annotations.MapBinder.createFormulatedValue()
Code:
StringBuilder fromAndWhereSb = new StringBuilder( " from " )
.append( associatedClass.getTable().getName() )
//.append(" as ") //Oracle doesn't support it in subqueries
.append( " " )
.append( alias ).append( " where " );
It looks like the schema were totally ignored here. I've patched this code snippet for my project, but the access to the "hibernate.default_schema" is not so easy from the MapBinder directly. The (Annotation)Configuration seems to be the last caller, who has access to those properties.
Code:
...
String schema = "";
if(properties != null)
schema = properties.getProperty("hibernate.default_schema");
if(associatedClass.getTable().getSchema()!=null)
schema = associatedClass.getTable().getSchema();
/** end dirty hack ***/
StringBuilder fromAndWhereSb = new StringBuilder( " from " )
/** begin dirty hack ***/
.append( " " )
.append(schema!=null && !schema.equals("") ? schema+"." : "")
/** end dirty hack ***/
.append( associatedClass.getTable().getName() )
//.append(" as ") //Oracle doesn't support it in subqueries
.append( " " )
.append( alias ).append( " where " );
I don't know, what to do with catalog, but for me is the adding of schema already enough. The properties were set as threadlocal within the AnnotationConfiguration, because i didn't want also to patch the hibernate-core.
It would be very nice, if someone could take a look on this place and find the "official" solution because this coding still be unchanged also in a 3.5 trunk. I use the Hibernate 3.3.2 + HibAnn 3.4.0 (latest)
Many thanks,
Gena