Skip to content

Commit f5c7d1b

Browse files
author
graeme
committed
fix for GRAILS-2002
git-svn-id: https://svn.codehaus.org/grails/trunk@6281 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
1 parent 1f24d11 commit f5c7d1b

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

src/persistence/org/codehaus/groovy/grails/orm/hibernate/cfg/GrailsDomainBinder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,12 @@ private static void bindSimpleValue(GrailsDomainClassProperty grailsProp, Simple
16421642
private static void setTypeForColumnConfig(GrailsDomainClassProperty grailsProp, SimpleValue simpleValue, ColumnConfig cc) {
16431643
if(cc != null && cc.getType() != null) {
16441644
Object type = cc.getType();
1645-
simpleValue.setTypeName(type.toString());
1645+
if(type instanceof Class) {
1646+
simpleValue.setTypeName(((Class)type).getName());
1647+
}
1648+
else {
1649+
simpleValue.setTypeName(type.toString());
1650+
}
16461651
}
16471652
else {
16481653
simpleValue.setTypeName(grailsProp.getType().getName());
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.codehaus.groovy.grails.orm.hibernate
2+
3+
import javax.sql.DataSource
4+
5+
/**
6+
* @author Graeme Rocher
7+
*/
8+
class UserTypeMappingTests extends AbstractGrailsHibernateTests{
9+
10+
protected void onSetUp() {
11+
gcl.parseClass '''
12+
import org.hibernate.type.*
13+
class UserTypeMappingTest
14+
{
15+
Long id
16+
Long version
17+
18+
Boolean active
19+
20+
static mapping = {
21+
table 'type_test'
22+
columns {
23+
active (column: 'active', type: YesNoType)
24+
}
25+
}
26+
}
27+
28+
29+
'''
30+
}
31+
32+
33+
void testUserTypeMapping() {
34+
35+
def clz = ga.getDomainClass("UserTypeMappingTest").clazz
36+
37+
38+
assert clz.newInstance(active:true).save(flush:true)
39+
40+
DataSource ds = (DataSource)applicationContext.getBean('dataSource')
41+
42+
def con
43+
try {
44+
con = ds.getConnection()
45+
def statement = con.prepareStatement("select * from type_test")
46+
def result = statement.executeQuery()
47+
assert result.next()
48+
def value = result.getString('active')
49+
50+
assertEquals "Y", value
51+
52+
} finally {
53+
con.close()
54+
}
55+
}
56+
57+
58+
}

0 commit comments

Comments
 (0)