views:

52

answers:

1

Hi, I am building data base system for electronic components. Unfortunatly other programs, that will use some of my tables need to have white spaces in column names. Ive tried in my hbm.xml file something like this with property:

...

property name="partGroup" column="part group" type="string"

...

of course hibernate wont create table with that column name.

Is there a way to do it using hibernate?

Thanks :]

+2  A: 

There is a way, enclose the table names or column names with backticks. From the documentation:

5.4. SQL quoted identifiers

You can force Hibernate to quote an identifier in the generated SQL by enclosing the table or column name in backticks in the mapping document. Hibernate will use the correct quotation style for the SQL Dialect. This is usually double quotes, but the SQL Server uses brackets and MySQL uses backticks.

<class name="LineItem" table="`Line Item`">
    <id name="id" column="`Item Id`"/><generator class="assigned"/></id>
    <property name="itemNumber" column="`Item #`"/>
    ...
</class>
Pascal Thivent
Thanks Pascal, stupid me :] thought quotes are only usefull when "case sensitive" names are important, didnt know that it also handles white spaces :]That will make my life in this project easier :)
Marek
@Marek You're welcome. Glad it was helpful.
Pascal Thivent