0
votes

I have something like this:

String statusCode

and in the mapping I have:

statusCode column: 'status_cd', type: 'NVARCHAR'

I have tried with 'varchar', 'VARCHAR' and 'nvarchar' I keep receiving

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor':
Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is org.hibernate.MappingException: Could not determine type for: NVARCHAR, at table: CARD, for columns: [org.hibernate.mapping.Column(status_cd)]
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)

Any idea what I may be missing in the mapping ? I am using grails 2.0 and MS SQL

2
Just fixed it, instead of type, I had to use sqlType: 'nvarchar'John

2 Answers

1
votes

Assuming "type: " there is equivalent to how Hibernate uses that term, then the problem is that type needs to refer to a Hibernate mapping type. That is to say, type is neither a java type nor a sql type. Its a Hibernate concept that understands the mapping between the two. Nationalized string support does not exist yet in Hibernate out-of-the-box (planned for 5.0). But its pretty easy to add.

First, you will need to define a Hibernate mapping type between Sting and NVARCHAR. You can accomplish this by either implementing a UserType or by extending one of the built-in Hibernate mapping types (org.hibernate.type.StringType would probably be a good starting point).

Then you name that implementation in your mapping.

1
votes

Steve Ebersole is right so I can add:

Set in you mapping a 'sqlType', try sqlType: "nvarchar", length: 255 ... Hibernate type, type: 'text' defaults to varchar