我正在使用EclipseLink 2.1.3和WebLogic 10.3.5容器管理事务来与Oracle 11g数据库连接。
我可以毫无问题地选择数据,但无法保留实体。
日志中没有引发异常或错误,但没有数据提交到ANNOUNCEMENT_DELIVERY_LOG表。
AnnouncementDeliveryLog实体与公告实体有@ManyToOne关系。我首先检索现有的公告实体,然后根据查询结果创建一个AnnouncementDeliveryLog实体,关联这两个实体,并保持不变。
关于我如何做错或如何从WebLogic上的EclipseLink获取更多日志信息的任何建议都将不胜感激。
@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;
}
@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();
}
}
@Stateless(name = "RecipientsPopulationTimer",
mappedName = "Announcements-AnnouncementDeliveryEngine-RecipientsPopulationTimer")
@Local({RecipientsPopulationTimerLocal.class})
public class RecipientsPopulationTimerBean implements RecipientsPopulationTimerLocal {
@EJB
DeliveryEngineSessionFacadeLocal sessionFacade;
}
<?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>
答案 0 :(得分:0)
RecipientsPopulationTimerBean正被一个超时的组件调用。
这意味着EJB事务被回滚,因为数据库事务花费的时间太长了。
在适当的数据库事务方法上设置@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
会阻止EJB超时和关联的数据库回滚。