I have a column in my SQL-2005 database that used to be a varchar(max), but it has been changed to an nvarchar(max).
Now I need to update my hibernate mapping file to reflect the change, and this is what it used to be:
<element type="text" column="Value"/>
When I try to run the application, the following error appears:
org.hibernate.HibernateException: Wrong column type in [Table] for column Value. Found: ntext, expected: text
What should I put in the 'type' attribute to correctly map the column as an nvarchar(max)?
I've tried setting the type to ntext, but hibernate didn't know what that was. I tried setting the type to string, but it treated string as a text type.
The key difference between varchar and nvarchar is the way they are stored, varchar is stored as regular 8-bit data(1 byte per character) and nvarchar stores data at 2 bytes per character. Due to this reason, nvarchar can hold upto 4000 characters and it takes double the space as SQL varchar.
The NVARCHAR(Max) data type stores variable-length character strings. NVARCHAR(Max) is used to store very large character data. NVARCHAR(Max) can hold as much as 2GB of Unicode character data. The word NVARCHAR stands for national varying character.
Columns with data types like nvarchar(max), text, and ntext cannot be used in indexes.
nvarchar max is for columns up to 2GB. So essentially it takes up more resources. You are better off using the nvarchar(50) if you know you aren't going to need that much space. each character is about 2 bytes so with 2 GB thats 1 billion characters...
What worked for me is to put the actual column definition in a @Column annotation:
@Column(name="requestXml", columnDefinition = "ntext")
private String request;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With