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.
分享到:
相关推荐
javaee实现jpa的toplink相关jar包。完整版。
toplink jpa的中文注解参考,虽然老了一点基本上还是很有用的。 原来下载的一个兄弟的chm,里面的锚链接有问题,反编译后修改了链接,并且保留html格式,使用更方便。
包括TOPLink JPA,Hibernate JPA,Open Jpa,jpa批注
myeclipse_jpa_toplink.swf
Oracle Toplink JPA
JPA文档_学TOPLINK必看_PDF格式
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用
jar包,官方版本,自测可用