From: <leg...@at...> - 2003-08-13 14:21:37
|
The following comment has been added to this issue: Author: Ethan Wolf Created: Wed, 13 Aug 2003 9:13 AM Body: No problem on going to the effort... I needed it for my work anyway. At your leisure, it would be great if you could give me a bit more info about what you mean by "changes to interfaces" so I can avoid wasting your time in the future. In fact, one of my goals was to keep the interface as you had it and change only implementation details of the SessionGenerator class (hence, the somewhat conceptually ugly nature of the fix). I did add a method and an instance variable, but they were private and meant only for the implementation. Thanks for any thoughts. Keep up the great work! --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-252 Here is an overview of the issue: --------------------------------------------------------------------- Key: HB-252 Summary: Sequence generation not qualified by default schema for Session Factory Type: Patch Status: Closed Priority: Minor Resolution: REJECTED Project: Hibernate2 Components: core Versions: 2.0.2 Assignee: Reporter: Ethan Wolf Created: Tue, 12 Aug 2003 1:54 PM Updated: Wed, 13 Aug 2003 2:07 AM Description: The sequence name (in ID generation) is not qualified by the default schema for the Session Factory (when no schema qualification is given in the mapping file). This limitation was reported on the forum: http://sourceforge.net/forum/message.php?msg_id=2056389 A partial fix was suggested, but did not work for session factories whose default schema is specified in a hibernate.cfg.xml configuration, rather than in hibernate.properties. It appears to be somewhat involved to make a fix in SequenceGenerator.configure(Type type, Properties params, Dialect dialect), since one must trace fairly far up the callstack to get access to the schema for the SessionFactory. Instead, a quicker/more localized fix was attained by performing the configuration of the schema qualification later, when a Session asks the SequenceGenerator for a sequence to be generated: SequenceGenerator.generate(SessionImplementor, Object). At that point, one can get to the SessionFactory from the session itself. While this is somewhat ugly, it appears to work in my tests (with Oracle). In order to implement this functionality, I made the following changes to SessionGenerator: 1. Added an instance variable so that the configuration only needs to get done the first time a session calls generate: private boolean isSequenceNameQualified = false; 2. Modified the configure method: public void configure(Type type, Properties params, Dialect dialect) throws MappingException { this.sequenceName = PropertiesHelper.getString(SEQUENCE, params, "hibernate_sequence"); String schemaName = params.getProperty(SCHEMA); // BEGIN BUGFIX EW if (sequenceName.indexOf(StringHelper.DOT) > 0) isSequenceNameQualified = true; else if (schemaName != null) { sequenceName = schemaName + '.' + sequenceName; isSequenceNameQualified = true; } // END BUGFIX returnClass = type.getReturnedClass(); sql = dialect.getSequenceNextValString(sequenceName); } 3. Added a method to configure the SessionGenerator the first time a Session calls generate: private void configureFor(SessionImplementor session) throws MappingException { String factorySchemaName = session.getFactory().getDefaultSchema(); if (factorySchemaName != null) sequenceName = factorySchemaName + '.' + sequenceName; isSequenceNameQualified = true; sql = session.getFactory().getDialect().getSequenceNextValString(sequenceName); } 4. Added a call to this method at the very start of the generate method: public Serializable generate(SessionImplementor session, Object obj) throws SQLException, HibernateException { // BUGFIX: EW Hibernate 2.0.2 When the SequenceGenerator is configured // it doesn't have access to the schema set for the default schema from the SessionFactory. if (!isSequenceNameQualified) { configureFor(session); } ...... } --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira |