Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Dali » "Generate Table from Entities" and reserved words
"Generate Table from Entities" and reserved words [message #667897] Mon, 02 May 2011 12:22 Go to next message
Roberto Viti is currently offline Roberto Viti
Messages: 1
Registered: May 2011
Junior Member
Hello to everyone!
I've just start to develop in Java EE 6 with "Eclipse Helios for web dev".

I've create my entities but when I trying to use the "Generate Table from Entities" tool, an error is popping out.

EL Warning]: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: 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 'Call (ID BIGINT NOT NULL, EXPIRIES DATE, NAME VARCHAR(255), PRIMARY KEY (ID))' at line 1
Error Code: 1064


Since MySQL 5.0, like they say here, "Call" is become a reserved word. Looking to the console output, the SQL statement that was passed to the DB is

CREATE TABLE CALL (ID BIGINT NOT NULL, EXPIRIES DATE, NAME VARCHAR(255), PRIMARY KEY (ID))


So the problem was there, but IMHO all the code got some problem. To comply MySQL's syntax recommendation, the code needs to be quite similar like this one

CREATE TABLE `RBDraft`.`CALL` (
  `id` BIGINT  NOT NULL,
  `epiries` DATE ,
  `name` VARCHAR(255) ,
  PRIMARY KEY (`id`)
)


And that one, passed to mysql, create a table named "Call" like i want.

I've try to force the small caps naming for the table by using the "@Table (name= "Call")" annotation in the entity code, but nothing is changed.

There's a way to force the correct syntax when I using the tool or it's easiest to change the entity name? Is it my fault or a bug?

[Am I asking in the right place?]

Thank you all, and sorry for my bad english.
Re: "Generate Table from Entities" and reserved words [message #667901 is a reply to message #667897] Mon, 02 May 2011 12:36 Go to previous messageGo to next message
Neil Hauge is currently offline Neil Hauge
Messages: 467
Registered: July 2009
Senior Member
Hi Roberto,

You are heading in the right direction by specifying the table name of the entity. Try also delimiting the table name with double quotes, which should give you the resulting SQL that you are looking for.

Example:

@Table (name= "\"Call\"")

This should do the trick. Do make sure that the case of 'call' is appropriate for your configuration as delimiting it will preserve the exact case as specified.

Neil
Re: "Generate Table from Entities" and reserved words [message #668056 is a reply to message #667901] Tue, 03 May 2011 10:43 Go to previous messageGo to next message
Neil Hauge is currently offline Neil Hauge
Messages: 467
Registered: July 2009
Senior Member
See the following bug for more details - https://bugs.eclipse.org/bugs/show_bug.cgi?id=344540
Re: "Generate Table from Entities" and reserved words [message #668060 is a reply to message #667897] Tue, 03 May 2011 10:57 Go to previous message
Brian Vosburgh is currently offline Brian Vosburgh
Messages: 131
Registered: July 2009
Senior Member
Roberto Viti wrote on Mon, 02 May 2011 12:22

There's a way to force the correct syntax when I using the tool or it's easiest to change the entity name? Is it my fault or a bug?



Dali delegates to your JPA runtime implementation, in this case EclipseLink, for the generation of tables from entities. So this is an EclipseLink bug most likely. I'm not sure of a workaround for the erroneous DDL generation; but you will need to use Neil's suggestion to get Dali to work once you do have the "Call" table built.

Also, you should be able to use MySQL standard backticks:

@Table (name= "`Call`")

instead of double-quotes if necessary. Double quotes will only work on MySQL if the ANSI_QUOTES SQL mode is enabled [1].

Brian

[1] http://dev.mysql.com/doc/refman/5.0/en/identifiers.html
Previous Topic:Can't browse schemas
Next Topic:Add JPA validator to JavaSE project
Goto Forum:
  


Current Time: Tue Jul 22 05:19:26 EDT 2014

Powered by FUDForum. Page generated in 0.01753 seconds