Hibernate Hell

S

Snyke

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
 
J

JScoobyCed

Snyke said:
[...]
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
[...]
<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>

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.
 
J

John Gagon

Snyke said:
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

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 (?,
?)
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
 
Joined
Jul 7, 2007
Messages
1
Reaction score
0
Hi all,

I am also using the Hibernate and Mysql5.1..... I am getting following error..
while executing or calling a procedure from hibernate in java using struts..

[ufollowup] DEBUG [http-8080-Processor23] SQL.log(393) | { call sp_get_email_template_text(?,?,?,?,? ,?,?,?,?,?,?) } [ufollowup] DEBUG [http-8080-Processor23] TemplateDaoHibernate.getTemplatePreview(173) | Exception . ....org.hibernate.MappingException: No Dialect mapping for JDBC type: -1

please tell me how to get rid of this error..its very very urgent to me....Pls help me...

Thanks in advance.
Satya.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top