JPA Toplink

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.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值