MS SQLServer numeric primary key hibernate

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

MS SQLServer numeric primary key hibernate

Gethin James
Hello,

By default Gorm/hiberate is generating id columns as the numeric(19,0) on SQLServer.  I'd like those to be of type BIGINT instead.

It's a well documented hibernate problemm, see http://opensource.atlassian.com/projects/hibernate/browse/HHH-3135?page=com.atlassian.jira.plugin.system.issuetabpanels%3aworklog-tabpanel and https://forum.hibernate.org/viewtopic.php?p=2377674#2377674

I tried to fix it with this Config.groovy entry:

grails.gorm.default.mapping = {
    id type:Long, sqlType:'BIGINT'
    version type:Long, sqlType:'BIGINT'
 }

That creates the tables ok but now my problem now is the all the foreign keys don't work:

Unsuccessful: alter table t add constraint FK23B9236D415D0D4 foreign key (y_id)
Column 'x' is not the same data type as referencing column 'y' in foreign key 'FK23B9236D415D0D4'.

I can't find any documentation on the grails foreign key types.
Any ideas?
Reply | Threaded
Open this post in threaded view
|

Re: MS SQLServer numeric primary key hibernate

Shane Petroff

I've never tried them but the mappings you list look like they should work. If it's creating the PK fine, I'm not sure how it would be messing up creating the FK. (Is Grails is creating both tables in the same run?)

Regardless, it's not really an answer, but in my case, I don't let Grails provision anything in the production db, so I just manually change any generated id's (pk and fk) in dev to bigint. If the mappings you listed below aren't working, you could define a custom hibernate dialect, but IMO it's not really worth the trouble to do more than fix it up in the db. Once altered in the db, Grails is fine working with MS SQL's bigint.

Shane


On 6/1/2011 5:00 AM, Gethin James wrote:
Hello,

By default Gorm/hiberate is generating id columns as the numeric(19,0) on SQLServer.  I'd like those to be of type BIGINT instead.

It's a well documented hibernate problemm, see http://opensource.atlassian.com/projects/hibernate/browse/HHH-3135?page=com.atlassian.jira.plugin.system.issuetabpanels%3aworklog-tabpanel and https://forum.hibernate.org/viewtopic.php?p=2377674#2377674

I tried to fix it with this Config.groovy entry:

grails.gorm.default.mapping = {
    id type:Long, sqlType:'BIGINT'
    version type:Long, sqlType:'BIGINT'
 }

That creates the tables ok but now my problem now is the all the foreign keys don't work:

Unsuccessful: alter table t add constraint FK23B9236D415D0D4 foreign key (y_id)
Column 'x' is not the same data type as referencing column 'y' in foreign key 'FK23B9236D415D0D4'.

I can't find any documentation on the grails foreign key types.
Any ideas?


-- 
Shane