JPA - Static metamodel and reserved keywords

528 views Asked by At

My entities have properties that translate to Java keywords. For example there is a Game entity and it has property private:

@Entity
public class Game
{
    //....

    private Boolean PRIVATE; //capitalized to avoid naming issues

    //no need for escaping or renaming, as "private" is not a database, JPA or SQL reserved identifier
    @Column
    public Boolean getPrivate() { return PRIVATE; } 

    //...
}

So far so good, until I generate a static metamodel for my entity and it is generated incorrectly:

@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(Game.class)
public abstract class Game_ extends AbstractEntity_ {

    public static volatile SingularAttribute<Game, Boolean> private; // <== compilation error

    //....
}

I use Hibernate metamodel generator, and I have no idea how to force it to rename problematic attributes. Is there a way to avoid naming problems in generated metamodel classes other than renaming attribute in question?

1

There are 1 answers

0
Steve Ebersole On

You are going to have to change it.

Hibernate and JPA defer to Java Beans with regard to naming conventions. Here you are creating a Java Bean property named "private"; nothing wrong with that per-se. I'm not sure what, if anything, Java Beans specifically says about such situations but its an anti-best practice at best.