`

JPA Toplink

    博客分类:
  • Java
阅读更多

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.


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics