Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Critical
-
Resolution: Fixed
-
Affects Version/s: 1.1-RC2
-
Fix Version/s: 1.1.1
-
Component/s: Persistence
-
Labels:None
-
Environment:Sun jdk 1.6.0_12, Grails 1.1-RC2, windows
-
Testcase included:yes
Description
The new enhanced getId() pattern for enums breaks in 1.1-RC2 if you specify a column name for the mapped enum.
Give the following class and enum:
enum FolderStatus { ACTIVE("activeValue"), DELETED("deletedValue"); final String id; FolderStatus(String id) { this.id = id; } } class Folder { FolderStatus folderStatus static mapping = { columns { folderStatus column: "folder_status" // <---- if we comment out this line, the test passes! } } }
the following test case will fail:
void testEnumPersistence() {
def folder = new Folder(folderStatus: FolderStatus.ACTIVE)
assertNotNull "Failed to save folder object", folder.save(flush:true)
sessionFactory.currentSession.clear()
def conn = sessionFactory.currentSession.connection()
def rs = conn.prepareStatement("SELECT folder_status FROM folder").executeQuery()
rs.next()
assertEquals "activeValue", rs.getString("folder_status")
}
The test fails on the last assert with the message:
expected:<[activeValue]> but was:<[ACTIVE]>
As the new enhanced enum support feature really shines when mapping legacy databases, not being able to specify a column name is a fairly
major hurdle. Per suggestion from Siegfried Puchbauer, I enabled logging for the classes:
org.codehaus.groovy.grails.orm.hibernate.cfg.IdentityEnumType and
org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder
Below is the log output where the highlighted section:
#a) does not get printed out when the column specification is enabled and the test fails
#b) does get printed out when the column specification is commented out and the test passes
...snip... Starting integration tests ... 2009-03-05 10:20:29,910 [main] DEBUG cfg.GrailsDomainBinder - [GrailsDomainBinder] Mapping Grails domain class: com.iteego.enumtest.Folder -> folder 2009-03-05 10:20:29,914 [main] DEBUG cfg.GrailsDomainBinder - [GrailsDomainBinder] bound property [id] to column name [id] in table [folder] 2009-03-05 10:20:29,915 [main] DEBUG cfg.GrailsDomainBinder - [GrailsDomainBinder] bound property [version] to column name [version] in table [folder] 2009-03-05 10:20:29,916 [main] DEBUG cfg.GrailsDomainBinder - [GrailsDomainBinder] Binding persistent property [folderStatus] <-- This section only gets printed then there is no column specification --> 2009-03-05 10:20:29,931 [main] DEBUG cfg.IdentityEnumType - Building ID-mapping for Enum Class com.iteego.enumtest.FolderStatus 2009-03-05 10:20:29,932 [main] DEBUG cfg.IdentityEnumType - Building Bidirectional Enum Map... 2009-03-05 10:20:29,943 [main] DEBUG cfg.IdentityEnumType - Mapped Basic Type is org.hibernate.type.StringType@68dc2d 2009-03-05 10:20:30,052 [main] DEBUG cfg.IdentityEnumType - Building ID-mapping for Enum Class com.iteego.enumtest.FolderStatus 2009-03-05 10:20:30,053 [main] DEBUG cfg.IdentityEnumType - Mapped Basic Type is org.hibernate.type.StringType@68dc2d 2009-03-05 10:20:30,053 [main] DEBUG cfg.IdentityEnumType - Building ID-mapping for Enum Class com.iteego.enumtest.FolderStatus 2009-03-05 10:20:30,053 [main] DEBUG cfg.IdentityEnumType - Mapped Basic Type is org.hibernate.type.StringType@68dc2d 2009-03-05 10:20:30,103 [main] DEBUG cfg.IdentityEnumType - Building ID-mapping for Enum Class com.iteego.enumtest.FolderStatus 2009-03-05 10:20:30,103 [main] DEBUG cfg.IdentityEnumType - Mapped Basic Type is org.hibernate.type.StringType@68dc2d 2009-03-05 10:20:30,104 [main] DEBUG cfg.IdentityEnumType - Building ID-mapping for Enum Class com.iteego.enumtest.FolderStatus 2009-03-05 10:20:30,104 [main] DEBUG cfg.IdentityEnumType - Mapped Basic Type is org.hibernate.type.StringType@68dc2d 2009-03-05 10:20:30,161 [main] DEBUG cfg.IdentityEnumType - Building ID-mapping for Enum Class com.iteego.enumtest.FolderStatus 2009-03-05 10:20:30,162 [main] DEBUG cfg.IdentityEnumType - Mapped Basic Type is org.hibernate.type.StringType@68dc2d <-- End of section --> Running tests of type 'integration' ...snip...
attaching a sample project with the above code and settings and with the tests failing.
Activity
- All
- Comments
- Work Log
- History
- Activity
- Git Commits
I'm having the same problem in version 1.3.7.