1.persistence.xml
--------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="hello-world" transaction-type="RESOURCE_LOCAL">
<provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>
<class>com.asran.toplink.Greeting</class>
<properties>
<property name="toplink.jdbc.url" value="jdbc:mysql://localhost:3306/toplink"/>
<property name="toplink.jdbc.user" value="root"/>
<property name="toplink.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="toplink.jdbc.password" value="123456"/>
<property name="toplink.ddl-generation" value="drop-and-create-tables"/>
<property name="toplink.logging.level.sql" value="FINE" />
</properties>
</persistence-unit>
</persistence>
2.logging(set in persistence.xml)
toplink.loging.level.<category>=<value>
Categories(defined in oracle.toplink.essentials.logging.SessionLog):
# sql - SQL logs
# transaction - Transaction related logs
# event
# connection - Session related logs
# query - DatabaseQuery related logs
# cache - shared cache logs
# propagation
# sequencing - sequencing generator logs
# ejb
# dms
# ejb_or_metadata - metadata processing logs
# weaver - class weaver logs
# properties - deployment time properties handler logs
Valid values are defined in java.util.logging.Level
If there is no category-specific level, the level set with toplink.logging.level(INFO is default) is used.
3. Cascade refresh query hint for refresh query
TLE provides the query hint toplink.refresh to fetch up-to-date entities from database like below.
Query query = em.createQuery("SELECT e FROM Employee e WHERE e.id = :id");
query.setHint("toplink.refresh", "true");
The associated entities will be refreshed also if they are specified with cascade=REFRESH. However the cascade metadata is static configuration which can not be changed in runtime and there may be some cases to apply different cascade options - do not cascade or cascade to all associations from time to time regardless of predefined cascade option. That is, more dynamic cascade refresh option can be useful. Hence I added the following query hint.
toplink.refresh.cascade=<value>
Control whether associated entities are refreshed.
The following are the valid values for the oracle.toplink.essentials.config.CascadePolicy:
* NoCascading - do not cascade at all
* CascadePrivateParts - cascade to private-owned associations
* CascadeAllParts - cascade to all associations
* CascadeByMapping - cascade by mapping metadata
Default is CascadeByMapping
Example:
import oracle.toplink.essentials.config.TopLinkQueryHints;
import oracle.toplink.essentials.config.CascadePolicy;
query.setHint(TopLinkQueryHints.REFRESH_CASCADE, CascadePolicy.CascadeAllParts);
or
query.setHint("toplink.refresh.cascade", "CascadeAllParts");
NOTE: This applies only if toplink.refresh is set to TRUE.
At this time CascadePrivateParts option has no difference from CascadeAllParts for Java Persistence Entity, but when using underlying TopLink feature this could behave different in the future.
分享到:
相关推荐
在Java EE环境中使用JPA TopLink,你需要包含相关的jar包以支持TopLink作为JPA的提供者。这些jar包通常包含了TopLink的实体管理器工厂、持久化单元配置、查询API以及其他必要的组件。"jpa_toplink"这个压缩包很可能...
TOPLink JPA是Oracle公司提供的一个JPA实现,它是TOPLink ORM工具的一部分。TOPLink JPA提供了完整的JPA规范支持,包括实体管理、查询语言(JPQL)以及事务处理。TOPLink JPA的优势在于其高性能和对复杂数据模型的...
**Toplink JPA注解参考** Toplink JPA(Java Persistence API)是Oracle公司提供的一种对象关系映射(ORM)框架,它允许开发者使用Java对象来操作数据库,而无需直接编写SQL语句。JPA提供了丰富的注解,使得在Java...
myeclipse_jpa_toplink.swf
总的来说,JPA文档中的"学TOPLINK必看"部分,会详细阐述如何配置和使用JPA,如何将TOPLINK的特性与JPA相结合,以及如何通过这些工具解决实际开发中的问题。通过阅读《JPA_Basic.pdf》,你将能够深入了解JPA的基础...
Oracle Toplink JPA
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
`toplink-essentials.jar`不仅实现了JPA规范,还包含了一些TopLink特有的高级特性,如对象缓存、事件监听、复杂查询以及对EJB QL的支持。通过这些功能,开发者可以实现高效的数据库访问和复杂的业务逻辑处理。 在...
Java Persistence API (JPA) 是Java企业版5(Java ...Oracle TopLink(现为EclipseLink)提供了对JPA 1.0规范以及许多扩展的支持,包括以前称为TopLink JPA的功能。更多信息和详细文档,可以访问EclipseLink官网获取。
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用