-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: @MapKey and @JoinTable ignores schema/catalog in formula
PostPosted: Wed Jan 20, 2010 12:08 pm 
Newbie

Joined: Mon Aug 28, 2006 6:31 am
Posts: 16
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.