reserved words and table names

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

reserved words and table names

Matthew Broadhead
i am trying to create a table called Condition but i get
javax.el.ELException: javax.enterprise.inject.CreationException:
org.apache.openjpa.lib.jdbc.ReportingSQLException: 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 'Condition

condition is a reserved word in MySQL.  is there a way to tell OpenJPA
to surround table and column names with backticks in queries?  i though
it would do that by default

Reply | Threaded
Open this post in threaded view
|

Re: reserved words and table names

Matthew Broadhead
in hibernate it is hibernate.globally_quoted_identifiers


On 11/05/18 16:41, Matthew Broadhead wrote:

> i am trying to create a table called Condition but i get
> javax.el.ELException: javax.enterprise.inject.CreationException:
> org.apache.openjpa.lib.jdbc.ReportingSQLException: 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 'Condition
>
> condition is a reserved word in MySQL.  is there a way to tell OpenJPA
> to surround table and column names with backticks in queries?  i
> though it would do that by default
>

Reply | Threaded
Open this post in threaded view
|

Re: reserved words and table names

Matthew Broadhead
In reply to this post by Matthew Broadhead
you may be right.  i just tried delimited identifiers but it tries to
add already existing fields

https://stackoverflow.com/questions/6791882/jpa-database-delimiters?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

now i might just go with @Table(name = "ConditionZ")


On 11/05/18 16:48, Sean McDowell wrote:

> Hi -- I tried to enable quoting in OpenJPA to deal with reserved
> keywords in MySQL.
>
> The feature seems very buggy and didn't work. I would recommend just
> avoiding keywords.
>
>
> Sean
>
>
>
> From: Matthew Broadhead <[hidden email]>
> To: [hidden email]
> Date: 11/05/2018 10:41 AM
> Subject: reserved words and table names
> ------------------------------------------------------------------------
>
>
>
> i am trying to create a table called Condition but i get
> javax.el.ELException: javax.enterprise.inject.CreationException:
> org.apache.openjpa.lib.jdbc.ReportingSQLException: 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 'Condition
>
> condition is a reserved word in MySQL.  is there a way to tell OpenJPA
> to surround table and column names with backticks in queries? i though
> it would do that by default
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

RE: reserved words and table names

Boblitz John
Hello Mathew,

I solved this by extended the Dictionary and overriding the toDBName methods.

    @Override
    public String toDBName(DBIdentifier name) {
        if (!getSupportsDelimitedIdentifiers()) {
            return name.getName();
        } else {
            for (String s : invalidColumnWordSet) {
                if (StringUtils.equalsIgnoreCase(s, name.getName())) {
                    String resp = getNamingUtil().delimit(name.getType().name(), name.getName(), true);
                    return resp;
                }
            }
        }
            return getNamingUtil().toDBName(name);
    }

    @Override
    public String toDBName(DBIdentifier name, boolean delimit) {
        if (!getSupportsDelimitedIdentifiers()) {
            return name.getName();
        } else {
            return getNamingUtil().toDBName(name, delimit);
        }
    }

This was for Postgres and your milage may vary...

Regards,

John Boblitz


> -----Original Message-----
> From: Matthew Broadhead [mailto:[hidden email]]
> Sent: Freitag, 11. Mai 2018 16:57
> To: [hidden email]
> Subject: Re: reserved words and table names
>
> you may be right.  i just tried delimited identifiers but it tries to add already
> existing fields
>
> https://stackoverflow.com/questions/6791882/jpa-database-
> delimiters?utm_medium=organic&utm_source=google_rich_qa&utm_campa
> ign=google_rich_qa
>
> now i might just go with @Table(name = "ConditionZ")
>
>
> On 11/05/18 16:48, Sean McDowell wrote:
> > Hi -- I tried to enable quoting in OpenJPA to deal with reserved
> > keywords in MySQL.
> >
> > The feature seems very buggy and didn't work. I would recommend just
> > avoiding keywords.
> >
> >
> > Sean
> >
> >
> >
> > From: Matthew Broadhead <[hidden email]>
> > To: [hidden email]
> > Date: 11/05/2018 10:41 AM
> > Subject: reserved words and table names
> > ----------------------------------------------------------------------
> > --
> >
> >
> >
> > i am trying to create a table called Condition but i get
> > javax.el.ELException: javax.enterprise.inject.CreationException:
> > org.apache.openjpa.lib.jdbc.ReportingSQLException: 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 'Condition
> >
> > condition is a reserved word in MySQL.  is there a way to tell OpenJPA
> > to surround table and column names with backticks in queries? i though
> > it would do that by default
> >
> >
> >
> >