user1224441
user1224441

Reputation:

If a property doesn't specify `column=` in the `hbm.xml`, what is the corresponding column's name in the table in the database?

In a hibernate mapping .xml file:

<hibernate-mapping>

  <class name="Customer" table="CUSTOMERS1">
    <id name="ssn"> <generator class="assigned" /> </id>
    <property name="firstName" column="FIRST_NAME"/>
    <property name="lastName" column="LAST_NAME"/>
  </class>

</hibernate-mapping>

<id name="ssn"> <generator class="assigned" /> </id> doesn't specify column=. What is the corresponding column's name in the table in the database?

The above comes from an example of Hibernate application. I want to test it on my laptop, so I am trying to create a table in a database before running the Hibernate application.

Thanks.

Upvotes: 1

Views: 1111

Answers (1)

Pankaj Gadge
Pankaj Gadge

Reputation: 2814

If you don't specify the column attribute, it defaults to the name property of id i.e. ssn in your case

<id
    name="propertyName"                                          
    type="typename"                                              
    column="column_name"                                         
    unsaved-value="null|any|none|undefined|id_value"             
    access="field|property|ClassName">                           
    node="element-name|@attribute-name|element/@attribute|."

    <generator class="generatorClass"/>
</id>
  • name (optional): the name of the identifier property.
  • type (optional): a name that indicates the Hibernate type.
  • column (optional - defaults to the property name): the name of the primary key column.
  • unsaved-value (optional - defaults to a "sensible" value): an identifier property value that indicates an instance is newly
    instantiated (unsaved), distinguishing it from detached instances
    that were saved or loaded in a previous session.
  • access (optional - defaults to property): the strategy Hibernate should use for accessing the property value.

Does it matter if I create a table with a column named SSN, instead of ssn?

If you want to make your column case insensitive, you have to enclose the column-names in your mappings in backticks, e.g. column="SSN", the backticks don't show here due to formatting though.

Source: https://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/mapping.html#mapping-declaration-id

Upvotes: 1

Related Questions