Hibernate配置文件标签汇总

本文详细介绍了Hibernate配置文件中的一些关键元素,包括`<hibernate-mapping>`、`<class>`、`<id>`、`<generator>`、`<version>`等。特别讨论了`<generator>`子元素的各种ID生成策略,如Increment、Identity、Hilo、seqhilo、Uuid.hex、Uuid.string、Native、Assigned和Foreign。这些策略在不同数据库环境下有不同的适用性和效果,开发者应根据项目需求选择合适的策略。
摘要由CSDN通过智能技术生成

1.<hibernate-mapping> Element
package: Fully qualifies unqualified classes in the mapping document. As you’ll see later, the
<class> element includes a name attribute that relates to the name of the Java class being
mapped. You can choose to use the package attribute and fully qualify the Java class. For
example:
<hibernate-mapping package="com.company">
<class name="Account"/>
</hibernate-mapping>
In this example, we're mapping the class com.company.Account. If we didn't add the
package attribute to the element, the system would expect to map a class called Account.
补充:这里class的路径都是以hibernate.cfg.xml/hibernate.propertites的目录为根目录进行定位。
schema: Like the package attribute, fully qualifies the table used in this particular mapping. If
you add the schema attribute, the supplied namespace is appended to the table. For example:
<hibernate-mapping schema="products">
<class table="CD"> </class>
</hibernate-mapping>
In this example, the fully qualified database/table is products.CD. The schema attribute is
optional.
2.<class> Element
name: Specifies the name of the Java class this mapping document is designed to represent.
Hibernate expects a fully qualified class name in this attribute if you don’t include the package
attribute in the <hibernate-mapping> element.
table: Specifies the name of the table to be used when persisting the Java object for this mapping.
schema: Overrides the value for the schema attribute specified in the <hibernate-mapping>
root element (if such a value has been set).
3.<id>  Element
name: Specifies the name of the ID. This is an optional attribute; it’s included in many mappings
with a value of "id".
type: Specifies the Hibernate type for the ID. If a type isn’t provided, Hibernate uses reflection
to try to determine the type. For a list of the Hibernate types, see the later description of the
<property> element.
column: Specifies the name of the database column. This is an optional attribute; if it isn’t specified,
the database column name is the value in the name attribute. You need to include either the
name or the column attribute in the <id> element.
unsaved-value: Determines whether a newly instantiated object needs to be persisted . This is an optional attribute; the default is null.
access: Specifies the way Hibernate accesses an object's attribute using traditional JavaBean
style setter/getter methods. The values available for the access attribute are field, property,
or a class name. If you want Hibernate to use reflection and access the Java object's attribute
directly, use the value "field". To build your own class for accessing the attribute of an object,
use as a value a class that implements net.sf.hibernate.property.PropertyAccessor.
<generator> subelement: Defined in the following section, “<generator> Element.”
4.<generator> Element
下面是各个generator的介绍:

Generator Description
increment It generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. It should not the used in the clustered environment.
identity It supports identity columns in DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL. T
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值