Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Hibernate Hell

Thread view: 
Snyke - 17 May 2006 02:31 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.