I'm having a hard time figuring out how to set up yes_no types to serve java.lang.Boolean values. I used to have it set up as a "java.lang.Boolean" value. That worked well with Firebird. But now, I have to move to SQL-Server, while keeping the same data structure. Whenever I try to insert a value in SQL-Server that contains the java.lang.Boolean type, there is a conversion to the "bit" type. I tried to change the query substitutions but I am still getting the error.
Conceptually, this seems like a no-brainer to me. Yet, it looks like I'm not understand something in the mapping flow. Is there something wrong with my setup or am I misunderstanding something or do I have to use a custom boolean type to make it work?
If my setup is wrong, what is wrong with it?
If I'm misunderstanding, what is it?
If I'm forced to use a custom boolean type, well, I guess I can figure how to do that but I think that's overkill. Hibernate offers everything I need.
Thanks,
L
Hibernate version: 2.1.6
Mapping documents:
Code:
#Hibernate properties for fmstatic
#Fri Oct 29 13:53:27 EDT 2004
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.dialect=net.sf.hibernate.dialect.SQLServerDialect
hibernate.show_sql=false
hibernate.connection.url=jdbc\:jtds\:sqlserver\://localhost\:1433;DatabaseName\=TmeData
hibernate.connection.driver_class=net.sourceforge.jtds.jdbc.Driver
hibernate.connection.provider_class=net.sf.hibernate.connection.C3P0ConnectionProvider
hibernate.query.substitutions=true 'Y', false 'N', yes 'Y', no 'N'
And for the class that interests me:
Code:
<property
name="userDefined"
type="yes_no"
update="true"
insert="true"
access="property"
column="user_defined"
not-null="true"
/>
My SQL scripts looks like this:
Code:
sp_addtype boolean, 'char(1)';
create table Profile
(
id UUID not null,
name NAMETYPE unique,
fw_id UUID not null,
hw_id UUID not null,
user_defined BOOLEAN,
constraint PK_Profile primary key (id)
);
Full stack trace of any exception that occurs: I'm using the jtds driver.
Code:
Oct 29, 2004 1:54:06 PM net.sf.hibernate.JDBCException <init>
SEVERE: Could not execute query
java.sql.SQLException: Syntax error converting the varchar value 'N' to a column of data type bit.
at net.sourceforge.jtds.jdbc.SQLDiagnostic.addDiagnostic(SQLDiagnostic.java:367)
at net.sourceforge.jtds.jdbc.TdsCore.tdsErrorToken(TdsCore.java:2217)
at net.sourceforge.jtds.jdbc.TdsCore.nextToken(TdsCore.java:1696)
at net.sourceforge.jtds.jdbc.TdsCore.isDataInResultSet(TdsCore.java:670)
at net.sourceforge.jtds.jdbc.JtdsResultSet.<init>(JtdsResultSet.java:139)
at net.sourceforge.jtds.jdbc.JtdsStatement.executeSQLQuery(JtdsStatement.java:277)
at net.sourceforge.jtds.jdbc.JtdsPreparedStatement.executeQuery(JtdsPreparedStatement.java:634)
at com.mchange.v2.sql.filter.FilterPreparedStatement.executeQuery(FilterPreparedStatement.java:68)
at com.mchange.v2.c3p0.impl.C3P0PooledConnection$2.executeQuery(C3P0PooledConnection.java:567)
at net.sf.hibernate.impl.BatcherImpl.getResultSet(BatcherImpl.java:87)
at net.sf.hibernate.loader.Loader.getResultSet(Loader.java:875)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:269)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:854)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1544)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1521)
Name and version of the database you are using: SQL Server 2000