Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

When you have a column of the bit data type what Class would be used to represent that in a Java POJO mapping that table to an object which is using javax.persistence annotations?

I tried Boolean, which didn't work and produced the following errors:

org.hibernate.exception.SQLGrammarException: could not insert: [com.DomainClassName]
java.sql.SQLException: Incorrect syntax near '-'.

EDIT: a Java boolean does map to the bit data type in SQL Server. I had a column name with a dash in it that I had to change.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Incorrect syntax near '-'.

This tells me that you've named a database, table or column with a dash in it, not that POJO is having an issue mapping your columns.

As an example, if you've named your entity bar-none and POJO issues the following CREATE TABLE statement:

CREATE TABLE dbo.foo(bar-none BIT);

Or this one:

CREATE TABLE dbo.foo-bar(none BIT);

You will get this error:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '-'.

And in fact even if you declare a data type that does not exist in SQL Server, such as Boolean, Frank or WhatTheHeckDataTypeIsThis, the parser will still barf with the above error due to the hyphen, before it even bothers validating the data type(s).

So, please check your table name and column names and be sure that your names don't use dashes, spaces or other special characters, that they aren't reserved words, and that each name you provide obeys the well-documented rules for identifiers. While you can get around this error if you can coerce POJO to properly delimit bad names with [square brackets], this is not a best practice.

share|improve this answer
Hibernate :( :( :( :( –  Phil Mar 6 '13 at 0:02
Yea you were right there was a dash in one of the fields. I was thinking it was one of the datatypes. Updated the column name and it worked. –  anataliocs Mar 6 '13 at 2:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.