I have two annotated Java classes that represent tables in my database.
One of the tables is a Customer table and there is a field that has the name "mtd-sales". When you issue a SQL statement through JDBC to get the value of that column, you need to wrap the column name in double quotes.
Code:
select "mtd-sales" from Customers
In my Hibernate annocations, I have the annotations for this column as follows:
Code:
private BigDecimal mtdSales;
@Basic
@Column(name="mtd-sales")
public BigDecimal getMtdSales() {
return mtdSales;
}
When I am extracting just this object from the database, everything works as it should.
But this object is also a related object to another table called Order.
So in my order class I have this:
Code:
private CustFileEntity custFileEntity;
@OneToOne
@JoinColumn(name="code")
public CustFileEntity getCustFileEntity() {
return this.custFileEntity;
}
What is interesting is that if I leave the code as I have it above, Hibernate will return the Customer objects if I ask for them directly, but I get a SQL exception when I try and get the order objects that each have a related customer object.
If I change my annotations in the customer class to this:
Code:
private BigDecimal mtdSales;
@Basic
@Column(name="\"mtd-sales\"")
public BigDecimal getMtdSales() {
return mtdSales;
}
( notice the escaped double quotes around the column name )
I get the reference effect, the customer objects are not returned when I ask for them directly, but are returned properly as related objects of the order class.
I am really confused what to do here.
I've also tried using the back tick instead of the escaped double quotes but I am getting the same results.