-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Escaping dashes in column names
PostPosted: Wed Oct 01, 2008 2:20 pm 
Newbie

Joined: Tue Apr 01, 2008 3:52 pm
Posts: 5
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.