You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by NathanM <na...@infdig.com> on 2009/05/16 01:45:08 UTC

NVARCHAR not supported?

Is NVarChar not supported? It seems to throw a lot of generation warnings in
ibator, and 

Generation Warnings Occured
  Unsupported Data Type in table .. ..  column:  ... ,property defaults to
Object type.
 
I'm running it against SQL Server, and there are plenty of NVARCHAR columns
in the data. 
-- 
View this message in context: http://www.nabble.com/NVARCHAR-not-supported--tp23568890p23568890.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: NVARCHAR not supported?

Posted by Jeff Butler <je...@gmail.com>.
Cool.  It should also work with the integrated Ant task in Eclipse.

Some day I'll get around to writing an Eclipse launcher which will
solve this problem for good in Eclipse - then I'll do away with the
simple "Generate..." menu option.  If only there was more time in the
day to write "fun" code.

Jeff


On Wed, May 20, 2009 at 3:13 PM, NathanM <na...@infdig.com> wrote:
>
> Thanks, that makes a big difference.
>
> While this won't work with the eclipse plugin, I got it to work from the
> command line and can probably get it to work with ant as well.
>
> Nathan
>
>
>
> Jeff Butler-2 wrote:
>>
>> You need to add your new resolver to the same classpath as the Ibator
>> JAR. <classPathEntry> elements are only used for JDBC drivers and one
>> other esoteric place.  Because your resolver extends an ibator class,
>> it should be loaded by the same classloader.
>>
>> http://ibatis.apache.org/docs/tools/ibator/configreference/classPathEntry.html
>>
>> Jeff Butler
>>
>>
>
> --
> View this message in context: http://www.nabble.com/NVARCHAR-not-supported--tp23568890p23642627.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

Re: NVARCHAR not supported?

Posted by NathanM <na...@infdig.com>.
Thanks, that makes a big difference. 

While this won't work with the eclipse plugin, I got it to work from the
command line and can probably get it to work with ant as well.  

Nathan 



Jeff Butler-2 wrote:
> 
> You need to add your new resolver to the same classpath as the Ibator
> JAR. <classPathEntry> elements are only used for JDBC drivers and one
> other esoteric place.  Because your resolver extends an ibator class,
> it should be loaded by the same classloader.
> 
> http://ibatis.apache.org/docs/tools/ibator/configreference/classPathEntry.html
> 
> Jeff Butler
> 
> 

-- 
View this message in context: http://www.nabble.com/NVARCHAR-not-supported--tp23568890p23642627.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: NVARCHAR not supported?

Posted by Jeff Butler <je...@gmail.com>.
You need to add your new resolver to the same classpath as the Ibator
JAR. <classPathEntry> elements are only used for JDBC drivers and one
other esoteric place.  Because your resolver extends an ibator class,
it should be loaded by the same classloader.

http://ibatis.apache.org/docs/tools/ibator/configreference/classPathEntry.html

Jeff Butler

On Mon, May 18, 2009 at 7:50 PM, NathanM <na...@infdig.com> wrote:
>
> Then what am I doing wrong with my resolver type?
>
> Ibator keeps failing with the "Cannot instantiate object . . . .
> JavaTypeResolverWithNVarChar";
>
> Does this instantiation not use the classpath entries in the
> ibatorConfig.xml file? I've tried putting an entry in there for the bin
> directory which has class files, and I've tried putting the custom resolver
> in a jar file and putting the jar file as a classpath entry.
>
> I have done a unit test and have no trouble loading this particular class.
>
> ==
>
> import java.sql.Types;
> import java.util.List;
> import java.util.Properties;
>
> import org.apache.ibatis.ibator.api.IntrospectedColumn;
> import org.apache.ibatis.ibator.api.JavaTypeResolver;
> import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
> import org.apache.ibatis.ibator.config.IbatorContext;
> import org.apache.ibatis.ibator.internal.types.JavaTypeResolverDefaultImpl;
>
> public class JavaTypeResolverWithNVarChar implements JavaTypeResolver {
>
>        JavaTypeResolverDefaultImpl impl = new JavaTypeResolverDefaultImpl();
>
>        public JavaTypeResolverWithNVarChar()
>        {
>
>
>        }
>
>        /* (non-Javadoc)
>         * @see
> org.apache.ibatis.ibator.api.JavaTypeResolver#addConfigurationProperties(java.util.Properties)
>         */
>        @Override
>        public void addConfigurationProperties(Properties properties) {
>                impl.addConfigurationProperties(properties);
>
>        }
>
>        /* (non-Javadoc)
>         * @see
> org.apache.ibatis.ibator.api.JavaTypeResolver#setIbatorContext(org.apache.ibatis.ibator.config.IbatorContext)
>         */
>        @Override
>        public void setIbatorContext(IbatorContext ibatorContext) {
>                impl.setIbatorContext(ibatorContext);
>        }
>
>        /* (non-Javadoc)
>         * @see
> org.apache.ibatis.ibator.api.JavaTypeResolver#setWarnings(java.util.List)
>         */
>        @Override
>        public void setWarnings(List<String> warnings) {
>                impl.setWarnings(warnings);
>        }
>
>
>        /**
>         * Override this method to add NVarChar to the list of supported types
>         */
>        @Override
>        public FullyQualifiedJavaType calculateJavaType(IntrospectedColumn
> introspectedColumn)
>        {
>        FullyQualifiedJavaType answer;
>                if(introspectedColumn.getJdbcType() == Types.NVARCHAR)
>                        answer = new FullyQualifiedJavaType(String.class.getName());
>                else
>                        answer = impl.calculateJavaType(introspectedColumn);
>                return answer;
>        }
> }
>
> ====
>
> Jeff Butler-2 wrote:
>>
>> As far as iBATIS goes, as long as the driver allows treating the
>> NVARCHAR column as VARCHAR, it should work out of the box.  If the
>> driver requires you to call the new JDBC 4.0 methods, then you'll have
>> to write a custom type handler.
>>
>> Jeff Butler
>>
>
> So I take it the SqlServer driver doesn't allow treating NVarChars as
> VARCHARS, or it would already work? I'm using the Microsoft sqljdbc4.jar
> driver.
>
>
> --
> View this message in context: http://www.nabble.com/NVARCHAR-not-supported--tp23568890p23607788.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

Re: NVARCHAR not supported?

Posted by NathanM <na...@infdig.com>.
Then what am I doing wrong with my resolver type? 

Ibator keeps failing with the "Cannot instantiate object . . . .
JavaTypeResolverWithNVarChar";

Does this instantiation not use the classpath entries in the
ibatorConfig.xml file? I've tried putting an entry in there for the bin
directory which has class files, and I've tried putting the custom resolver
in a jar file and putting the jar file as a classpath entry. 

I have done a unit test and have no trouble loading this particular class. 

==

import java.sql.Types;
import java.util.List;
import java.util.Properties;

import org.apache.ibatis.ibator.api.IntrospectedColumn;
import org.apache.ibatis.ibator.api.JavaTypeResolver;
import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
import org.apache.ibatis.ibator.config.IbatorContext;
import org.apache.ibatis.ibator.internal.types.JavaTypeResolverDefaultImpl;

public class JavaTypeResolverWithNVarChar implements JavaTypeResolver {
	
	JavaTypeResolverDefaultImpl impl = new JavaTypeResolverDefaultImpl();
	
	public JavaTypeResolverWithNVarChar()
	{


	}
	
	/* (non-Javadoc)
	 * @see
org.apache.ibatis.ibator.api.JavaTypeResolver#addConfigurationProperties(java.util.Properties)
	 */
	@Override
	public void addConfigurationProperties(Properties properties) {
		impl.addConfigurationProperties(properties);
		
	}

	/* (non-Javadoc)
	 * @see
org.apache.ibatis.ibator.api.JavaTypeResolver#setIbatorContext(org.apache.ibatis.ibator.config.IbatorContext)
	 */
	@Override
	public void setIbatorContext(IbatorContext ibatorContext) {
		impl.setIbatorContext(ibatorContext);
	}

	/* (non-Javadoc)
	 * @see
org.apache.ibatis.ibator.api.JavaTypeResolver#setWarnings(java.util.List)
	 */
	@Override
	public void setWarnings(List<String> warnings) {
		impl.setWarnings(warnings);
	}


	/**
	 * Override this method to add NVarChar to the list of supported types
	 */
	@Override
	public FullyQualifiedJavaType calculateJavaType(IntrospectedColumn
introspectedColumn)
	{
        FullyQualifiedJavaType answer;
		if(introspectedColumn.getJdbcType() == Types.NVARCHAR)
			answer = new FullyQualifiedJavaType(String.class.getName());
		else
			answer = impl.calculateJavaType(introspectedColumn);
		return answer;
	}
}

==== 

Jeff Butler-2 wrote:
> 
> As far as iBATIS goes, as long as the driver allows treating the
> NVARCHAR column as VARCHAR, it should work out of the box.  If the
> driver requires you to call the new JDBC 4.0 methods, then you'll have
> to write a custom type handler.
> 
> Jeff Butler
> 

So I take it the SqlServer driver doesn't allow treating NVarChars as
VARCHARS, or it would already work? I'm using the Microsoft sqljdbc4.jar
driver. 


-- 
View this message in context: http://www.nabble.com/NVARCHAR-not-supported--tp23568890p23607788.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: NVARCHAR not supported?

Posted by Jeff Butler <je...@gmail.com>.
Currently, you have these options with Ibator:

1. Write your own type resolver
2. Use column overrides on each NVARCHAR column

I've got an idea for the Ibator type resolver where you can configure
this globally, but there's no scheduled delivery date for that.

As far as iBATIS goes, as long as the driver allows treating the
NVARCHAR column as VARCHAR, it should work out of the box.  If the
driver requires you to call the new JDBC 4.0 methods, then you'll have
to write a custom type handler.

Jeff Butler


On Mon, May 18, 2009 at 3:31 PM, NathanM <na...@infdig.com> wrote:
>
> I've tried a test case and casting it to a String works. It also gave the
> correct string value. I have not tried an actual UTF-16 valeu because I
> don't know how to enter one in SQL Server Management Studio.
>
> What is the best way to generate code to retrieve nvarchar as a string?
> Should I use a plugin or some config parameters?
>
> Nathan
>
> --
> View this message in context: http://www.nabble.com/NVARCHAR-not-supported--tp23568890p23604538.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>

Re: NVARCHAR not supported?

Posted by NathanM <na...@infdig.com>.
I've tried a test case and casting it to a String works. It also gave the
correct string value. I have not tried an actual UTF-16 valeu because I
don't know how to enter one in SQL Server Management Studio.  

What is the best way to generate code to retrieve nvarchar as a string?
Should I use a plugin or some config parameters?

Nathan 

-- 
View this message in context: http://www.nabble.com/NVARCHAR-not-supported--tp23568890p23604538.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


Re: NVARCHAR not supported?

Posted by Jeff Butler <je...@gmail.com>.
NVARCHAR is not a supported data type in JDBC before JDBC 4.0 (Java SE
6).  iBATIS does not support JDBC 4.0 currently, neither does Ibator.

However, you may find that casting the generated Object variable to a
String will work.  Try it and let us know.

Jeff Butler


On Fri, May 15, 2009 at 6:45 PM, NathanM <na...@infdig.com> wrote:
>
> Is NVarChar not supported? It seems to throw a lot of generation warnings in
> ibator, and
>
> Generation Warnings Occured
>  Unsupported Data Type in table .. ..  column:  ... ,property defaults to
> Object type.
>
> I'm running it against SQL Server, and there are plenty of NVARCHAR columns
> in the data.
> --
> View this message in context: http://www.nabble.com/NVARCHAR-not-supported--tp23568890p23568890.html
> Sent from the iBATIS - User - Java mailing list archive at Nabble.com.
>
>