0

我正在使用带有 WebLogic 10.3.5 容器管理事务的 EclipseLink 2.1.3 与 Oracle 11g DB 交互。

我可以毫无问题地选择数据,但无法持久化实体。

日志中没有引发异常或错误,但没有数据提交到 ANNOUNCEMENT_DELIVERY_LOG 表。

AnnouncementDeliveryLog 实体与 Announcement 实体具有 @ManyToOne 关系。我首先检索一个现有的 Announcement Entity,然后根据查询结果创建一个 AnnouncementDeliveryLog Entity,将这两个 Entities 关联,并持久化。

任何关于我做错了什么或如何从 WebLogic 上的 EclipseLink 获取更多日志信息的建议都将不胜感激。

AnnouncementDeliveryLog 实体:

@Entity
@Table(name = "ANNOUNCEMENT_DELIVERY_LOG")
public class AnnouncementDeliveryLog implements Serializable {

    @Id
    @Column(nullable = false)
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="ANNOUNCEMENT_DELIVERY_LOG_SEQ")
    @SequenceGenerator(name="ANNOUNCEMENT_DELIVERY_LOG_SEQ", sequenceName="ANNOUNCEMENT_DELIVERY_LOG_SEQ")
    private BigDecimal id;
    @Column(name = "RECIPIENT_ADDRESS ", nullable = false, unique = true, length = 240)
    private String recipientAddress;
    @ManyToOne
    @JoinColumn(name = "ANNOUNCEMENT_ID ")
    private Announcements announcement;
}

公告实体:

@Entity
@Table(name = "ANNOUNCEMENTS")
public class Announcements implements Serializable {
    @Id
    @Column(nullable = false)
    private BigDecimal id;
    @OneToMany(mappedBy = "announcement")
    private List<AnnouncementDeliveryLog> announcementDeliveryLogList;
}

会话外观 SLSB 执行事务:

@Stateless(name = "DeliveryEngineSessionFacade",
           mappedName = "Announcements-JMSDeliveryEngine-DeliveryEngineSessionFacade")
public class DeliveryEngineSessionFacadeBean implements DeliveryEngineSessionFacadeLocal {
    @Resource
    SessionContext sessionContext;
    @PersistenceContext(unitName = "JMSDeliveryEnginePersistenceUnit")
    private EntityManager em;

    private List<AnnouncementDeliveryLog> createNormalizedEmailADLsForAnnouncement(int announcementId) {
        List<Object[]> rawResultList;
        ArrayList<AnnouncementDeliveryLog> typedResultList = new ArrayList<AnnouncementDeliveryLog>();

        Query query =
            em.createNamedQuery(AnnouncementDeliveryLog.FIND_NORMALIZED_RECIPIENTS_FOR_ANNOUNCEMENT);
        query.setParameter(1, announcementId);
        rawResultList = query.getResultList();

        for (Object[] resultElement : rawResultList) {
            AnnouncementDeliveryLog adl = new AnnouncementDeliveryLog(getAnnouncementById(announcementId), (String)resultElement[1], (String)resultElement[2], "TO_SEND");
            adl = persistAnnouncementDeliveryLog(adl);
            typedResultList.add(adl);
        }

        return typedResultList;
    }

public AnnouncementDeliveryLog persistAnnouncementDeliveryLog(AnnouncementDeliveryLog announcementDeliveryLog) {
    em.persist(announcementDeliveryLog);
    return announcementDeliveryLog;
}

public Announcements getAnnouncementById(int announcementId) {
    Query query = em.createNamedQuery(Announcements.FIND_BY_ID);
    query.setParameter("id", announcementId);
    return (Announcements)query.getSingleResult();
}

}

SLSB 调用会话外观:

@Stateless(name = "RecipientsPopulationTimer",
           mappedName = "Announcements-AnnouncementDeliveryEngine-RecipientsPopulationTimer")
@Local({RecipientsPopulationTimerLocal.class})
public class RecipientsPopulationTimerBean implements RecipientsPopulationTimerLocal {
    @EJB
    DeliveryEngineSessionFacadeLocal sessionFacade;
}

持久性.xml

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
             version="2.0">
    <persistence-unit name="JMSDeliveryEnginePersistenceUnit">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/announcementsDS</jta-data-source>
        <class>announcements.deliveryengine.jpa.entities.AnnEmailRecipientsFlattened</class>
        <class>announcements.deliveryengine.jpa.entities.AnnImRecipientsFlattened</class>
        <class>announcements.deliveryengine.jpa.entities.AnnouncementDeliveryLog</class>
        <class>announcements.deliveryengine.jpa.entities.Announcements</class>
        <class>announcements.deliveryengine.jpa.entities.AnnouncementRecipients</class>
        <class>announcements.deliveryengine.jpa.entities.AnnouncementRecipientsFlattenedId</class>
        <properties>
            <property name="eclipselink.target-server" value="WebLogic 10"/>
            <property name="eclipselink.logging.level" value="FINE"/>
            <property name="eclipselink.logging.exceptions" value="true"/>
            <property name="eclipselink.logging.timestamp" value="true"/>
            <property name="eclipselink.logging.thread" value="true"/>
            <property name="eclipselink.logging.session" value="true"/>
            <property name="eclipselink.logging.level.sql" value="FINE"/>
            <property name="eclipselink.logging.parameters" value="true"/>
            <property name="eclipselink.target-database" value="Oracle11"/>
        </properties>
    </persistence-unit>
</persistence>
4

1 回答 1

0

RecipientsPopulationTimerBean 被一个有超时的组件调用。

这意味着 EJB 事务被回滚,因为 DB 事务花费了太长时间。

设置@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)适当的 DB 事务方法可防止 EJB 超时和关联的 DB 回滚。

于 2013-03-14T12:32:12.877 回答