在 hibernate 映射中.xml
文件:
<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>
未指定column=
。数据库表中对应的列名是什么?
以上来自Hibernate应用程序的示例。我想在我的笔记本电脑上测试它,因此我尝试在运行 Hibernate 应用程序之前在数据库中创建一个表。
谢谢。
最佳答案
如果您不指定column
属性,则默认为id
的name
属性,即ssn
对于你的情况
<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.
如果我创建一个包含名为 SSN(而不是 ssn)的列的表,这有什么关系吗?
如果您想让列不区分大小写,则必须将映射中的列名称用反引号括起来,例如column="
SSN"
,但由于格式原因,此处不显示反引号。
来源:https://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/mapping.html#mapping-declaration-id
关于java - 如果属性在 `column=` 中没有指定 `hbm.xml` ,那么数据库表中对应的列名是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47764329/