|
I tried to use a very simple table legacy, with no id and no version
class Disease { String code String desc static mapping = { id name:"code" code column:"DIS_ID_A" version false } } I generate all but it doesn't work if the values of code are numeric. I edit the gsp generated replacing id with code so I'm able the list.gsp and the show.gsp working but the problem is the action edit of the controller def diseaseInstance = Disease.get(params.id) I get error org.hibernate.TypeMismatchException Provided id of the wrong type for class com.spark.Disease. Expected: class java.lang.String, got class java.lang.Long I debugged, the value passed is a String "001" but internal there is some conversion. I think The question is Is possible with grails to manage a so simple table? If the values of code are non numeric it works, but I think they use numeric codes for fast input where is the source code of get? Thanks in advance for any suggestions Paolo |
|
Hello Paolo
try to set column name and type for id static mapping = { id name:"code", column:'code', type:'string' code column:"DIS_ID_A" version false } } org.grails.datastore.gorm.GormStaticApi.get
Thanks
Grygoriy Mykhalyuno www.grygoriy.com |
|
Thanks for the quick reply!
I try to set the type as you suggest but it doesn't work |
|
That is what I just try
CREATE TABLE Disease ( code varchar, description varchar ); INSERT INTO Disease VALUES ('1-1', 'desc 1'); INSERT INTO Disease VALUES ('1-2', 'desc 1'); class Disease { String code String description static constraints = { } static mapping = { table 'Disease' id name: 'code', column: 'code', type: 'string' columns { code column: 'code', type: 'string' } version false } } in my controller Disease.get('1-1') works for me. I still see that id type is Long but Disease.get('1-1') gets what I want
Thanks
Grygoriy Mykhalyuno www.grygoriy.com |
|
it works because '1-1' is String , please try with '1' and '2'
I try to cast but it seems that there is some internal conversion |
|
yes, Looks like grails cast it beck from serializable to Long. Id is still type of long not string.
you may try use quick solution Disease.findByCode('4') and maybe make sense to rize jira issue
Thanks
Grygoriy Mykhalyuno www.grygoriy.com |
|
This post was updated on .
here is a solution
please add explicitly id field to your domain class Disease { String id String code String description static constraints = { } static mapping = { table 'Disease' id name: 'code', column: 'code', type: 'string' columns { code column: 'code', type: 'string' } version false } } after that Disease.get('4') works as expected I think this issue is similar http://jira.grails.org/browse/GRAILS-4467
Thanks
Grygoriy Mykhalyuno www.grygoriy.com |
| Powered by Nabble | Edit this page |
