How to change varchar to nvarchar in mssql using hibernate
Tech-Today

How to change varchar to nvarchar in mssql using hibernate


In my recent assignment I was asked to change how hibernate creates a table changing varchar fields to nvarchar. The problem is in MSSQL we need an nvarchar to support UTF-8 characters.

We are actually using a JDBC MSSQL driver available here:
http://technet.microsoft.com/en-us/library/ms378422.aspx

This driver needs to be configured inside jboss, the server I'm on.

First you need to extend SQLServerDialect and override the VARCHAR definition.
package org.kbs.hibernate.dialect;

import java.sql.Types;

import org.hibernate.HibernateException;
import org.hibernate.dialect.SQLServerDialect;

public class MSSQLServerDialect extends SQLServerDialect {

public UnicodeSQLServerDialect() {
super();

registerColumnType(Types.VARCHAR, "nvarchar($l)");
registerColumnType(Types.BIGINT, "bigint");
registerColumnType(Types.BIT, "bit");
}

}

Second you need to tell hibernate to use your new class:
<property name="hibernate.dialect" value="org.kbs.hibernate.dialect.MSSQLServerDialect" />

Reference:
http://grepcode.com/file/repo1.maven.org/maven2/org.hibernate/hibernate-core/3.3.1.GA/org/hibernate/dialect/SQLServerDialect.java




- Wildfly Server Provisioning Elastic Search Integration
I'm interested and would like to evaluate the integration of Elasticsearch to hibernate-search. I'm using the Wildfly container, however, Wildfly's hibernate-search library is a bit outdated: 5.5.8. so I need to find a way to outdate the jars...

- How To Run Activiti In Glassfish/postgresql In Jta Mode
What you need: 1.) Glassfish 2.) Postgresql - make sure that max_transactions is set to at least 10. Otherwise you will encounter the no session error because by default the value is 0. 3.) Checkout travelexpenses from: https://svn.camunda.com/fox/demo/activiti-cdi/travelexpenses/trunk/...

- Passing An Array Of Objects To Mssql Stored Procedure
Oftentimes you need to pass an array of objects (could be ids, types, etc) in an mssql stored procedure that you either need to insert into a table or use as filter. The following codes will explain the latter: Pass an array of integers: ALTER PROCEDURE...

- Java.lang.nosuchmethodexception: Org.hibernate.validator.classvalidator
Note I'm using jboss-5.1.0.GA If you ever encounter the following error: Caused by: org.hibernate.AnnotationException: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.(java .lang.Class, java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator,...

- How To Get Started With Hibernate In Java. Create A Simple Class And Database Schema For Demostration.
Since, I've always been using different database sometimes I get confused how to implement the others. Like hibernate, where the configuration must be properly set. *This help assumes that you have already created a java project in eclipse that has...



Tech-Today








.