如何在不重新启动服务器的情况下刷新更新的实体数据 [英] How to refresh updated entity data without restarting the server

查看:129
本文介绍了如何在不重新启动服务器的情况下刷新更新的实体数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中将EclipseLink JPA用作ORM,将Web逻辑10.3用作应用程序服务器.一切正常,直到出现数据刷新错误为止.在这种情况下,我的实体表行之一已更新为新值,但我的实体管理器或JPA没有选择该值.为此,我们只能依靠它重新启动服务器.然后它获取了值.

I am using EclipseLink JPA as ORM and web logic 10.3 as an application server in my project. Everything working fine until i got a bug for data refresh. Here is the case one of my entity table row is updated to new value but my entity manager or JPA did not pick that value. For this we have lite rely re started the server. then it picked up the value.

这是我的persistence.xml文件,这是我在课堂上使用实体管理器的方式.

Here is my persistence.xml file and here is the way i am using entity manager in my class.

<persistence-unit name="BasePersistenceUnit" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/CTH_DS</jta-data-source> 
    <class>org.test.partyrequest.model.dataobject.RqstTrc</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>

    <properties>
        <property name="eclipselink.target-server" value="WebLogic_10" />
        <!-- Logging level is set to INFO, Need to change in Production -->
        <property name="eclipselink.logging.level" value="FINE" />
        <property name="eclipselink.persistence-context.flush-mode" value="COMMIT" />
        <property name="eclipselink.persistence-context.close-on-commit" value="true" />
        <property name="eclipselink.cache.shared.default" value="false" />      
    </properties>
</persistence-unit>

SPRING JPA XML文件

SPRING JPA XML FILE

<context:load-time-weaver aspectj-weaving="on" />

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="BasePersistenceUnit" />
</bean>

<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter" />

<bean id="transactionManager" class="org.springframework.transaction.jta.WebLogicJtaTransactionManager" /> 

<!-- ========================= BUSINESS OBJECT DEFINITIONS ========================= -->

<!-- Instruct Spring to perform declarative transaction management automatically on annotated classes. -->
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>

<!-- Post-processor to perform exception translation on @Repository classes
    (from native exceptions such as JPA PersistenceExceptions to Spring's DataAccessException hierarchy).
-->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

我的实体失事

@Entity

@Table(name ="PRTY_RQST") 公共类PrtyRqst实现了Serializable {

@Table(name = "PRTY_RQST") public class PrtyRqst implements Serializable {

private static final long serialVersionUID = -4679712398918736694L;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PRTY_RQST_PRTYRQSTID_GENERATOR")
@SequenceGenerator(name = "PRTY_RQST_PRTYRQSTID_GENERATOR", allocationSize = 1, sequenceName = "PRTY_RQST_SEQ")
@Column(name = "PRTY_RQST_ID")
private Long prtyRqstId;

@Column(name = "CHLD_RQST_IND")
private String chldRqstInd;

@Column(name = "PARNT_PRTY_RQST_ID")
private BigDecimal parntPrtyRqstId;

@Column(name = "PROCES_REFR")
private String procesRefr;

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "RQST_DT_TM")
private Date rqstDtTm;

@Column(name = "UPDT_BY")
private String updtBy;

// bi-directional many-to-one association to PrtyKey
@OneToMany(mappedBy = "prtyRqst", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<PrtyKey> prtyKeys;

// bi-directional many-to-one association to PrtyRqstHist
@OneToMany(mappedBy = "prtyRqst", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@OrderBy("rqstDtTm DESC")
private List<PrtyRqstHist> prtyRqstHists;

@OneToOne(mappedBy = "prtyRqst", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private RqstPayload rqstPayload;

// bi-directional many-to-one association to RqstTrc
@OneToMany(mappedBy = "prtyRqst", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<RqstTrc> rqstTrcs;

// bi-directional many-to-one association to AddtnRqstInfo
@OneToMany(mappedBy = "prtyRqst", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<AddtnRqstInfo> addtnRqstInfos;

// bi-directional many-to-one association to BusnApplc
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
@JoinColumn(name = "BUSN_APPLC_ID")
private BusnApplc busnApplc;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
@JoinColumn(name = "INTN_PROCES_TYP_ID")
private IntnProcesTyp intnProcesTyp;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
@JoinColumn(name = "INTN_STATS_ID")
private IntnStat intnStat;

@Column(name = "ORCHESTRATION_ID")
private String orchestrationId;

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
@JoinColumn(name = "ALLW_CHNL_ID")
private AllwChnl allwChnl;

// bi-directional many-to-one association to RqstTyp
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.REFRESH)
@JoinColumn(name = "RQST_TYP_ID")
private RqstTyp rqstTyp;

@Column(name = "TRACK_RQST_IND")
private String trackRqstInd;

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "SUBMIT_DT_TM")
private Date submitDtTm;

@Temporal(TemporalType.DATE)
@Column(name = "EFFECTIVE_DT")
private Date effectiveDt;

@Temporal(TemporalType.TIMESTAMP)
@Column(name = "RQST_CREATE_DT_TM")
private Date rqstCreateDtTm;

在我的DAO IMPL课堂上,我有this.persist(prtyRqstDO);

In my DAO IMPL class I have this.persist(prtyRqstDO);

@Transactional(readOnly = true, propagation=Propagation.REQUIRED)
    private PartyRequestBO createRequest(PartyRequestBO partyRequestBO, boolean isParent) throws RuntimeException {
        if (log.isDebugEnabled()) {
            log.debug("Enter: PartyRequestsDAOImpl:createRequest()");
        }
        partyRequestBO.setOrchestrationID(generateOrchestrationId());
        PrtyRqst prtyRqstDO = PartyRequestEntityMapper.partyRequestMapper(partyRequestBO, isParent, true);
        try {
            this.persist(prtyRqstDO);
            partyRequestBO.setRequestIdentifier(prtyRqstDO.getPrtyRqstId());
        } catch (Exception e) {
            if(log.isDebugEnabled()) {
                log.debug("PartyRequestsDAOImpl:createRequest : " + PartyRequestConstants.UNABLE_TO_INSERT, e);
            }
            throw new PartyRequestDataException(PartyRequestConstants.UNABLE_TO_INSERT, e);
        }
        if (log.isDebugEnabled()) {
            log.debug("Exit: PartyRequestsDAOImpl:createRequest()");
        }
        return partyRequestBO;
    }


@Transactional(readOnly = true, propagation=Propagation.REQUIRED)
public void persist(T entity) {
    if (log.isDebugEnabled()) {
        log.debug("Enter: BaseDAO:persist() : " + entity);
    }
    this.getEntityManager().persist(entity);
    if (log.isDebugEnabled()) {
        log.debug("Exit: BaseDAO:persist()");
    }
}
public EntityManager getEntityManager() {
    if (log.isDebugEnabled()) {
        log.debug("Enter: BaseDAO:getEntityManager() : " + this.entityManager);
    }
    return this.entityManager;
}

这里的问题是,如果我通过后端更新其中一个表中的行,则我的应用程序容器没有选择更改.

Here the problem is, if i update the row in one of the table through back end my application container is not picking the change.

有人可以告诉我吗?预先谢谢你.

Can any one Tell me? thank you in advance.

谢谢你们俩.我已经根据您在代码行中添加的注释进行了修改.

Thank you both of you. I have modified according to your comments added following lines of code.

this.entityManager.clear();
this.entityManager.close();
//this.getEntityManager().refresh(entityManager);

在这里,我可以通过后端获得更新值,而无需重新启动服务器.但是问题在于它保留了所有更改的值.

Here i could able to get the update value what i have done it through backend with out restarting server. But the problem is it hold all the changed values.

例如,我已将其值更改为 FulOrderWSA ,它正在工作.更改为 FulorderWSB ,它又可以正常工作.现在,我尝试了 FulOrderWSZ ,它不起作用(数据库值为FulorderWSB).

for example i have changed value to FulOrderWSA it was working. changed to FulorderWSB it was working again.Now i have tried for FulOrderWSZ it didn't work(DB values is FulorderWSB ).

最后,我在这里尝试使用 FulorderWSA 的旧值,根据数据库,它不起作用,但对我有用.我注意到它保留了所有数据库更改的值.

Finally i tried here with old value that is FulorderWSA as per DB it should not work but it worked for me. what i noticed that it is holding all the DB changed values here.

如何驾驭它.我已经使用了clear和close作为entityManager.谁可以帮我这个事.

How to get ride of this. I have used both clear and close for entityManager. can any one help me on this.

谢谢.

维杰.

推荐答案

谢谢

为您提供所有支持.基本上,我们不使用EclipseLink中的Cache.我们有将所有元数据初始化都作为init方法处理的bean.我们要做的是,使用JDK Timer重新加载特定的Bean以刷新数据.一切正常.

for all your support. Basically we are not using Cache from EclipseLink. we had bean that handles all the metadata initialization as init method. what we have done is, used JDK Timer to reload the particular Bean to refresh the data. It was working fine.

我检查了刷新所有方法所花费的时间少于500毫秒.我可以预见只有在执行此线程并且有一个请求时才会出现问题.因为它占用的时间少于500毫秒.

I have checked the time taking to refresh the all the methods are less than 500 milliseconds. I can foresee only issue when this thread is executing and there is a request.since it is taking less than 500 millisecs its ok for us.

如果有人不使用缓存,希望对您有所帮助.

I hope this will be helpful if someone is not using cache you can try this approach.

谢谢.

这篇关于如何在不重新启动服务器的情况下刷新更新的实体数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆