Ok, I must admit that I'm pretty new to Hibernate but I can't get over
this error without help...
I have a class Privilege that is mapped to a MySQL Table. It has just 2
boolean values read and write, but I keep running into syntax errors
wether I want to create the database or insert a record:
03:21:58,339 ERROR SchemaExport:271 - Unsuccessful: create table privs
(id bigint not null auto_increment, read bit, write bit, primary key
(id))
03:21:58,340 ERROR SchemaExport:272 - You have an error in your SQL
syntax; check the manual that corresponds to your MySQL server version
for the right syntax to use near 'read bit, write bit, primary key
(id))' at line 1
03:21:58,341 INFO SchemaExport:202 - schema export complete
03:21:58,490 DEBUG SQL:346 - insert into privs (read, write) values (?,
?)
Hibernate: insert into privs (read, write) values (?, ?)
03:21:58,519 WARN JDBCExceptionReporter:71 - SQL Error: 1064,
SQLState: 42000
03:21:58,520 ERROR JDBCExceptionReporter:72 - You have an error in your
SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near 'read, write) values ('0',
'0')' at line 1
The statements look ok to me, but MySQL doesn't seem to like them for
some obscure reason...
Anyway my configuration looks like this:
<hibernate-configuration>
<session-factory>
<property
name="connection.url">jdbc:mysql://localhost/test</property>
<property name="connection.username">root</property>
<property
name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property
name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.password"></property>
<property
name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.hbm2ddl.auto">create-drop</property>
[...]
</session-factory>
</hibernate-configuration>
And my mapping file like this:
<hibernate-mapping>
<class name="net.snyke.tmm.Privilege" table="privs">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="read"/>
<property name="write"/>
</class>
</hibernate-mapping>
Basically hibernate should create the tables and then insert one entry,
but both queries fail...
Any idea?
Thanks for your time,
Christian 'Snyke' Decker
http://www.Snyke.net
Danno - 17 May 2006 03:19 GMT
That's not Hibernate's fault.....you are using mySQL reserved words,
iow you can't have a field called read or write.
http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
Snyke - 17 May 2006 03:27 GMT
Thanks alot Danno,
it did the trick ^^
JScoobyCed - 17 May 2006 03:23 GMT
> [...]
> 03:21:58,520 ERROR JDBCExceptionReporter:72 - You have an error in your
[quoted text clipped - 11 lines]
> </class>
> </hibernate-mapping>
Quite simple: 'read' and 'write' are keywords in MySQl (and maybe in
many DBMS) Change them to a different name and it will fix your problem.

Signature
JSC
John Gagon - 17 May 2006 07:36 GMT
> Ok, I must admit that I'm pretty new to Hibernate but I can't get over
> this error without help...
[quoted text clipped - 11 lines]
> (id))' at line 1
> 03:21:58,341 INFO SchemaExport:202 - schema export complete
Hibernate Hell here seems directly proportional to the "Xml Hell". My
guess though is that you have some syntax issue with perhaps reserved
words or unrecognized words for your version. Maybe read bit and
write bit are not recognized with your version as modifiers for a
unique auto incrementing id field.
John Gagon
> 03:21:58,490 DEBUG SQL:346 - insert into privs (read, write) values (?,
> ?)
[quoted text clipped - 46 lines]
> Christian 'Snyke' Decker
> http://www.Snyke.net