JAVA PERSISTENCE API (JPA)
13.2.1. About JPA
The Java Persistence API (JPA) is the standard for using persistence in Java projects. Java EE 6 applications use the Java Persistence 2.0 specification, documented here: http://www.jcp.org/en/jsr/detail?id=317.
Hibernate EntityManager implements the programming interfaces and life-cycle rules defined by the specification. It provides JBoss EAP 6 with a complete Java Persistence solution.
JBoss EAP 6 is 100% compliant with the Java Persistence 2.0 specification. Hibernate also provides additional features to the specification.
To get started with JPA and JBoss EAP 6, refer to the bean-validation, greeter, and kitchensink quickstarts: Section 1.4.1.1, “Access the Quickstarts”.
13.2.4. Configuration
13.2.4.1. Hibernate Configuration Properties
Table 13.1. Hibernate Java Properties
Property Name | Description |
---|---|
hibernate.dialect |
The classname of a Hibernate
org.hibernate.dialect.Dialect . Allows Hibernate to generate SQL optimized for a particular relational database.In most cases Hibernate will be able to choose the correct
org.hibernate.dialect.Dialect implementation, based on the JDBC metadata returned by the JDBC driver. |
hibernate.show_sql |
Boolean. Writes all SQL statements to console. This is an alternative to setting the log category
org.hibernate.SQL to debug . |
hibernate.format_sql |
Boolean. Pretty print the SQL in the log and console.
|
hibernate.default_schema |
Qualify unqualified table names with the given schema/tablespace in generated SQL.
|
hibernate.default_catalog |
Qualifies unqualified table names with the given catalog in generated SQL.
|
hibernate.session_factory_name |
The
org.hibernate.SessionFactory will be automatically bound to this name in JNDI after it has been created. For example, jndi/composite/name . |
hibernate.max_fetch_depth |
Sets a maximum "depth" for the outer join fetch tree for single-ended associations (one-to-one, many-to-one). A
0 disables default outer join fetching. The recommended value is between 0 and 3 . |
hibernate.default_batch_fetch_size |
Sets a default size for Hibernate batch fetching of associations. The recommended values are
4 , 8 , and 16 . |
hibernate.default_entity_mode |
Sets a default mode for entity representation for all sessions opened from this
SessionFactory . Values include: dynamic-map , dom4j , pojo . |
hibernate.order_updates |
Boolean. Forces Hibernate to order SQL updates by the primary key value of the items being updated. This will result in fewer transaction deadlocks in highly concurrent systems.
|
hibernate.generate_statistics |
Boolean. If enabled, Hibernate will collect statistics useful for performance tuning.
|
hibernate.use_identifier_rollback |
Boolean. If enabled, generated identifier properties will be reset to default values when objects are deleted.
|
hibernate.use_sql_comments |
Boolean. If turned on, Hibernate will generate comments inside the SQL, for easier debugging. Default value is
false . |
hibernate.id.new_generator_mappings |
Boolean. This property is relevant when using
@GeneratedValue . It indicates whether or not the new IdentifierGenerator implementations are used for javax.persistence.GenerationType.AUTO , javax.persistence.GenerationType.TABLE and javax.persistence.GenerationType.SEQUENCE . Default value is true . |
hibernate.ejb.naming_strategy |
Chooses the
org.hibernate.cfg.NamingStrategy implementation when using Hibernate EntityManager. This class is deprecated and this property is only provided for backward compatibility. This property must not be used with hibernate.ejb.naming_strategy_delegator .If the application does not use EntityManager, follow the instructions here to configure the NamingStrategy: Hibernate Reference Documentation - Implementing a Naming Strategy.
|
hibernate.ejb.naming_strategy_delegator |
Specifies an
org.hibernate.cfg.naming.NamingStrategyDelegator implementation for database objects and schema elements when using Hibernate EntityManager. This property has the following possible values.
NOTE This property must not be used with
hibernate.ejb.naming_strategy . It is a temporary replacement for org.hibernate.cfg.NamingStrategy to address its limitations. A more comprehensive solution is planned for Hibernate 5.0 that replaces both org.hibernate.cfg.NamingStrategy and org.hibernate.cfg.naming.NamingStrategyDelegator .If the application does not use EntityManager, follow the instructions here to configure the NamingStrategy: Hibernate Reference Documentation - Implementing a Naming Strategy.
|
IMPORTANT
hibernate.id.new_generator_mappings
, new applications should keep the default value of true
. Existing applications that used Hibernate 3.3.x may need to change it to false
to continue using a sequence object or table based generator, and maintain backward compatibility.13.2.4.2. Hibernate JDBC and Connection Properties
Table 13.2. Properties
Property Name | Description |
---|---|
hibernate.jdbc.fetch_size |
A non-zero value that determines the JDBC fetch size (calls
Statement.setFetchSize() ). |
hibernate.jdbc.batch_size |
A non-zero value enables use of JDBC2 batch updates by Hibernate. The recommended values are between
5 and 30 . |
hibernate.jdbc.batch_versioned_data |
Boolean. Set this property to
true if the JDBC driver returns correct row counts from executeBatch() . Hibernate will then use batched DML for automatically versioned data. Default value is to false . |
hibernate.jdbc.factory_class |
Select a custom
org.hibernate.jdbc.Batcher . Most applications will not need this configuration property. |
hibernate.jdbc.use_scrollable_resultset |
Boolean. Enables use of JDBC2 scrollable resultsets by Hibernate. This property is only necessary when using user-supplied JDBC connections. Hibernate uses connection metadata otherwise.
|
hibernate.jdbc.use_streams_for_binary |
Boolean. This is a system-level property. Use streams when writing/reading
binary or serializable types to/from JDBC. |
hibernate.jdbc.use_get_generated_keys |
Boolean. Enables use of JDBC3
PreparedStatement.getGeneratedKeys() to retrieve natively generated keys after insert. Requires JDBC3+ driver and JRE1.4+. Set to false if JDBC driver has problems with the Hibernate identifier generators. By default, it tries to determine the driver capabilities using connection metadata. |
hibernate.connection.provider_class |
The classname of a custom
org.hibernate.connection.ConnectionProvider which provides JDBC connections to Hibernate. |
hibernate.connection.isolation |
Sets the JDBC transaction isolation level. Check
java.sql.Connection for meaningful values, but note that most databases do not support all isolation levels and some define additional, non-standard isolations. Standard values are 1, 2, 4, 8 . |
hibernate.connection.autocommit |
Boolean. This property is not recommended for use. Enables autocommit for JDBC pooled connections.
|
hibernate.connection.release_mode |
Specifies when Hibernate should release JDBC connections. By default, a JDBC connection is held until the session is explicitly closed or disconnected. The default value
auto will choose after_statement for the JTA and CMT transaction strategies, and after_transaction for the JDBC transaction strategy.Available values are
auto (default), on_close , after_transaction , after_statement .This setting only affects
Session returned from SessionFactory.openSession . For Session obtained through SessionFactory.getCurrentSession , the CurrentSessionContext implementation configured for use controls the connection release mode for that Session . |
hibernate.connection.<propertyName> |
Pass the JDBC property <propertyName> to
DriverManager.getConnection() . |
hibernate.jndi.<propertyName> |
Pass the property <propertyName> to the JNDI
InitialContextFactory . |
13.2.4.3. Hibernate Cache Properties
Table 13.3. Properties
Property Name | Description |
---|---|
hibernate.cache.region.factory_class |
The classname of a custom
CacheProvider . |
hibernate.cache.use_minimal_puts |
Boolean. Optimizes second-level cache operation to minimize writes, at the cost of more frequent reads. This setting is most useful for clustered caches and, in Hibernate3, is enabled by default for clustered cache implementations.
|
hibernate.cache.use_query_cache |
Boolean. Enables the query cache. Individual queries still have to be set cacheable.
|
hibernate.cache.use_second_level_cache |
Boolean. Used to completely disable the second level cache, which is enabled by default for classes that specify a
<cache> mapping. |
hibernate.cache.query_cache_factory |
The classname of a custom
QueryCache interface. The default value is the built-in StandardQueryCache . |
hibernate.cache.region_prefix |
A prefix to use for second-level cache region names.
|
hibernate.cache.use_structured_entries |
Boolean. Forces Hibernate to store data in the second-level cache in a more human-friendly format.
|
hibernate.cache.default_cache_concurrency_strategy |
Setting used to give the name of the default
org.hibernate.annotations.CacheConcurrencyStrategy to use when either @Cacheable or @Cache is used. @Cache(strategy="..") is used to override this default. |
13.2.4.4. Hibernate Transaction Properties
Table 13.4. Properties
Property Name | Description |
---|---|
hibernate.transaction.factory_class |
The classname of a
TransactionFactory to use with Hibernate Transaction API. Defaults to JDBCTransactionFactory ). |
jta.UserTransaction |
A JNDI name used by
JTATransactionFactory to obtain the JTA UserTransaction from the application server. |
hibernate.transaction.manager_lookup_class |
The classname of a
TransactionManagerLookup . It is required when JVM-level caching is enabled or when using hilo generator in a JTA environment. |
hibernate.transaction.flush_before_completion |
Boolean. If enabled, the session will be automatically flushed during the before completion phase of the transaction. Built-in and automatic session context management is preferred.
|
hibernate.transaction.auto_close_session |
Boolean. If enabled, the session will be automatically closed during the after completion phase of the transaction. Built-in and automatic session context management is preferred.
|
https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.4/html/Development_Guide/sect-Java_Persistence_API_JPA.html
JAVA PERSISTENCE API (JPA)的更多相关文章
- Hibernate操作指南-搭建一个简单的示例(基于Java Persistence API JPA)
- JPA(Java Persistence API)Java持久化API-介绍
JPA全称: Java Persistence API JPA的宗旨是为POJO提供持久化标准规范,能够脱离容器独立运行,很方便开发和测试.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关 ...
- 关于注解-Hebernate与JPA(java persistence api)
The JPA spec. defines the JPA annotation in the javax.persistence package. Hibernate not only implem ...
- Java Persistence API(转)
定义 Java Persistence API JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中.[编辑本段]起源 Sun引入新的JPA ORM规范 ...
- Java EE (4) -- Java EE 6 Java Persistence API Developer Certified Expert(1z0-898)
Overview of the Java Persistence API Describe the basics of Object Relational Mapping (ORM) Define t ...
- java中配置JPA方法
JPA全称Java Persistence API.JPA通过JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到数据库中 使用JPA进行保存对象时,可以用对象来接收,例 ...
- Java | 基础归纳 | JPA
https://www.javacodegeeks.com/2015/04/jpa%E5%85%A5%E9%97%A8%E6%95%99%E7%A8%8B.html JPA 全称====>Jav ...
- Java Persistence with MyBatis 3(中国版)
译者的话 前段时间因为工作和学习的须要,我打算深入研究MyBatis框架.于是在网上查找关于MyBatis的教程,发现国内网上关于MyBatis的教程资料少得可怜:除了MyBatis官网上的用户使用手 ...
- 【Other】最近在研究的, Java/Springboot/RPC/JPA等
我的Springboot框架,欢迎关注: https://github.com/junneyang/common-web-starter Dubbo-大波-服务化框架 dubbo_百度搜索 Dubbo ...
随机推荐
- 网站系统压力测试Jmeter+Badboy
最近项目需要压力测试,因此搜了几款试用,首选的是LoadRunner这款大名鼎鼎的测试软件: LoadRunner11 下载请猛戳这里 传送门LoadRunner破解文件 下载请猛戳这里 传送门Loa ...
- ruby rails_autolink不能加载的原因
从rails 3.1.0开始,默认在ActionView::Helper::TextHelper中的auto_link方法已经被移除,放到了第三方的gem里:rails_autolink.遂想试一下其 ...
- ruby如何查找一个方法属于哪个类
这是一个看似简单,实际不那么直接的问题.一种方法是先直接看当前对象的类是神马东东: puts self.class 或者 self.class.name 不过在某些情况下上述代码返回不了具体的名称,前 ...
- 基于Redis的分布式锁两种实现方式
最近有一个竞拍的项目会用到分布式锁,网上查到的结果是有三种途径可以实现.1.数据库锁机制,2.redis的锁,3.zookeeper.考虑到使用mysql实现会在性能这一块会受影响,zookeeper ...
- 工作中常用Git指令操作
常用Git指令总结 前阵子有几天好不顺,可谓是喝水都呛着,更何况被Git给呛着了,还不轻,哈哈.所以打算总结一下自己在工作使用到Git相关的东西以及和大家探讨使用GIt的心得体会.于是,关于Git的的 ...
- 搭建spring cloud config
很久没更新了,因为不是专职研究spring cloud,因此更新速度得看工作强度大不大,每天能抽出的时间不多,如果更新太慢了,并且有小伙伴看的话,请见谅了. Spring Cloud简介 Spring ...
- Google高级搜索技巧十则
前言:多数人在使用Google搜索的过程是非常低效和无谓的,如果你只是输入几个关键词,然后按搜索按钮,你将是那些无法得到Google全部信息的用户,在这篇文章中,Google搜索专家迈克尔.米勒将向您 ...
- 数据库导入Excel数据的简易方法
当然,最糙猛的方式就是自己写程序读取Excel程序然后插进数据库,但那种方式要求太高.说个简单方法,主流数据库的管理工具支持CSV文件格式数据向表导入,而Excel可以另存外CSV文件,这种导入就手工 ...
- DDGScreenShot — 复杂屏幕截屏(如view ScrollView webView wkwebView)
写在前面 最近有这么一个需求,分享页面,分享的是web订单截图,既然是web 就会有超出屏幕的部分, 生成的图片还要加上我们的二维码,这就涉及到图片的合成了. 有了这样的需求,就是各种google.也 ...
- 深入理解SpringBoot之自动装配
SpringBoot的自动装配是拆箱即用的基础,也是微服务化的前提.其实它并不那么神秘,我在这之前已经写过最基本的实现了,大家可以参考这篇文章.这次主要的议题是,来看看它是怎么样实现的,我们透过源代码 ...