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 :]
Column names can contain any valid characters (for example, spaces).
To select a column name with spaces, use the back tick symbol with column name. The symbol is ( ` `). Back tick is displayed in the keyboard below the tilde operator ( ~).
hibernate. type. Type[] columnTypes = getSessionFactory(). getClassMetadata(Employee.
Table names can contain any valid characters (for example, spaces).
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With