Uploaded image for project: 'Hibernate ORM'
  1. HHH-9805

Column name specified in @JoinColumn is not quoted with option hibernate.globally_quoted_identifiers=true


    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.3.10
    • Fix Version/s: 4.3.11
    • Component/s: hibernate-core
    • Labels:
    • Environment:
      database = PostgreSQL 9.4
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
    • Sprint:


      We want to support H2 and PostgreSQL, so there is no opition with manually adding quotes around every identification. And we use flag hibernate.globally_quoted_identifiers=true instead. But it happen that it doesn't work for column names in @JoinColumn annotation!

      Suppose we have 2 entity classes:

      public class City extends Entity {
      @Column(name = "sName", nullable = false)
      private String name;

      @ManyToOne(fetch = FetchType.EAGER)
      @JoinColumn(name = "nID_Region", insertable = false, updatable = false, nullable = false)
      private Region region;

      public String getName()

      { return name; }

      public void setName(String name)

      { this.name = name; }

      public Region getRegion()

      { return region; }

      public void setRegion(Region region)

      { this.region = region; }

      public class Region extends Entity {
      @Column(name = "sName", nullable = false)
      private String name;

      @OneToMany(mappedBy = "region", cascade = CascadeType.ALL, orphanRemoval = true)
      @OrderBy("name asc")
      private List<City> cities;

      public String getName()

      { return name; }

      public void setName(String name)

      { this.name = name; }

      public List<City> getCities()

      { return cities; }

      public void setCities(List<City> cities)

      { this.cities = cities; }


      and base class:
      public abstract class Entity {

      private Integer id;

      public Integer getId()

      { return id; }

      public void setId(Integer id)

      { this.id = id; }


      session factory:
      <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
      <property name="dataSource" ref="dataSource"/>
      <property name="packagesToScan">

      <property name="hibernateProperties">
      <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL9Dialect</prop>
      <prop key="hibernate.globally_quoted_identifiers">true</prop>
      <prop key="hibernate.show_sql">true</prop>

      Here is generated query:
      Hibernate: select cities0_.nID_Region as nID_Regi3_2_0, cities0_."nID" as nID1_1_0, cities0_."nID" as nID1_1_1, cities0_."sName" as sName2_1_1, cities0_.nID_Region as nID_Regi3_1_1 from "City" cities0 where cities0_.nID_Region=? order by cities0_."sName" asc

      as you can see all is quoted except : nID_Region
      which in the end leads to exception.




            • Votes:
              0 Vote for this issue
              4 Start watching this issue


              • Created: