|
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:
{{@javax.persistence.Entity 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; }
} }} @javax.persistence.Entity public class Region extends Entity { @Column(name = "sName", nullable = false) private String name;
@OneToMany(mappedBy = "region", cascade = CascadeType.ALL, orphanRemoval = true) @LazyCollection(LazyCollectionOption.FALSE) @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: @MappedSuperclass public abstract class Entity {
@Id @Column(name="nID") private Integer id;
@Identifier 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"> <array> <value>org.wf.dp.dniprorada.model</value> </array> </property>
<property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQL9Dialect</prop> <prop key="hibernate.globally_quoted_identifiers">true</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean>
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.
|