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:matthew.broadh...@nbmlaw.co.uk]
> Sent: Freitag, 11. Mai 2018 16:57
> To: users@openjpa.apache.org
> 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 <matthew.broadh...@nbmlaw.co.uk>
> > To: users@openjpa.apache.org
> > 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 via email to