【问题标题】:Entity is not weaved. Eclipselink 2.1 + Dynamic Weaving实体未编织。 Eclipselink 2.1 + 动态编织
【发布时间】:2011-06-27 22:02:39
【问题描述】:

我有一个在 tomcat 上运行的 Java EE 应用程序,它带有几个实体类并使用 eclipselink 2.1 和 jpa 2.0。 实体是 EmailNotification 和 EmailNotificationQueueRow。

@Entity
public class EmailNotification implements Serializable, IEntity<Integer> {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "emailGen")
@SequenceGenerator(name = "emailGen", sequenceName = "SQ_EMAIL_NOTIFICATIONS", allocationSize=1)
@Basic(optional = false)
@Column(name = "EMAIL_ID")
private Integer emailId;
@Basic(optional = false)
@Column(name = "EMAIL_SUBJECT")
private String emailSubject;
@Basic(optional = false)
@Column(name = "EMAIL_BODY")
private String emailBody;
@Basic(optional = false)
@Column(name = "SENT_FROM_EMAIL_ADDRESS")
private String sentFromEmailAddress;
@Column(name = "SEND_TO_ORG_ID")
private Integer sendToOrgId;
@Column(name = "SEND_TO_EMAIL_ADDRESS")
private String sendToEmailAddress;
@Column(name = "CARBON_COPY_ORG_ID")
private Integer carbonCopyOrgId;
@Column(name = "CARBON_COPY_EMAIL_ADDRESS")
private String carbonCopyEmailAddress;
@Column(name = "BCC_ORG_ID")
private Integer bccOrgId;
@Column(name = "BCC_EMAIL_ADDRESS")
private String bccEmailAddress;
@Column(name = "PROJECT_ID")
private Integer projectId;

//getters and setters
}

@Entity
public class EmailNotificationQueueRow implements Serializable, IEntity<Integer> {

private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "EMAIL_QUEUE_ID")
private Integer emailQueueId;
@Basic(optional = false)
@Column(name = "EMAIL_ID")
private int emailId;
@Basic(optional = false)
@Column(name = "REQUEST_DATE")
@Temporal(TemporalType.TIMESTAMP)
private Date requestDate;
@Basic(optional = false)
@Column(name = "MESSAGE_SENT_FLAG")
private String messageSentFlag;
@Column(name = "MESSAGE_SENT_DATE")
@Temporal(TemporalType.TIMESTAMP)
private Date messageSentDate;
@JoinColumn(name = "EMAIL_ID", referencedColumnName = "EMAIL_ID", updatable = false, insertable = false)
@OneToOne(fetch = FetchType.LAZY)
private EmailNotification emailNotification;

//getters and setters
}

每当我将 emailNotification 变量的关系设置为 FetchType.LAZY(如上)时,该类就不会被编织。它已注册编织,但从未注册。

日志如下。 EmailNotification 实体是编织的,但不是 EmailNotificationQueueRow 实体。有什么想法吗?

[EL Config]: 2011-02-15 14:21:13.642--ServerSession(1191324)--Thread(Thread[main,5,main])
--The access type for the persistent class [class persistence.model.EmailNotification] is set to [FIELD].
[EL Config]: 2011-02-15 14:21:13.674--ServerSession(1191324)--Thread(Thread[main,5,main])
--The access type for the persistent class [class persistence.model.EmailNotificationQueueRow] is set to [FIELD].
[EL Config]: 2011-02-15 14:21:13.674--ServerSession(1191324)--Thread(Thread[main,5,main])
--The target entity (reference) class for the one to one mapping element [field emailNotification] is being defaulted to: class persistence.model.EmailNotification.
[EL Config]: 2011-02-15 14:21:13.689--ServerSession(1191324)--Thread(Thread[main,5,main])
--The alias name for the entity class [class persistence.model.EmailNotification] is being defaulted to: EmailNotification.
[EL Config]: 2011-02-15 14:21:13.72--ServerSession(1191324)--Thread(Thread[main,5,main])
--The alias name for the entity class [class persistence.model.EmailNotificationQueueRow] is being defaulted to: EmailNotificationQueueRow.
[EL Finer]: 2011-02-15 14:21:13.736--ServerSession(1191324)--Thread(Thread[main,5,main])
--Class [persistence.model.EmailNotification] registered to be processed by weaver.
[EL Finer]: 2011-02-15 14:21:13.799--ServerSession(1191324)--Thread(Thread[main,5,main])
--Class [persistence.model.EmailNotificationQueueRow] registered to be processed by weaver.
[EL Finest]: 2011-02-15 14:21:13.799--ServerSession(1191324)--Thread(Thread[main,5,main])
--End predeploying Persistence Unit iDMS_Persistence_Unit; session file:/C:/idms/build/web/WEB-INF/classes/_iDMS_Persistence_Unit; state Predeployed; factoryCount 1
[EL Finest]: 2011-02-15 14:21:13.908--ServerSession(1191324)--Thread(Thread[main,5,main])
--Begin weaver class transformer processing class [persistence/model/EmailNotification].
[EL Finest]: 2011-02-15 14:21:13.924--ServerSession(1191324)--Thread(Thread[main,5,main])
--Weaved persistence (PersistenceEntity) [persistence/model/EmailNotification].
[EL Finest]: 2011-02-15 14:21:13.924--ServerSession(1191324)--Thread(Thread[main,5,main])
--Weaved change tracking (ChangeTracker) [persistence/model/EmailNotification].
[EL Finest]: 2011-02-15 14:21:13.986--ServerSession(1191324)--Thread(Thread[main,5,main])
--Weaved fetch groups (FetchGroupTracker) [persistence/model/EmailNotification].
[EL Finest]: 2011-02-15 14:21:13.986--ServerSession(1191324)--Thread(Thread[main,5,main])
--End weaver class transformer processing class [persistence/model/EmailNotification].

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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_1_0.xsd">
  <persistence-unit name="iDMS_Persistence_Unit" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/dms</jta-data-source>
    <class>persistence.model.EmailNotification</class>
    <class>persistence.model.EmailNotificationQueueRow</class>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
  <properties>
    <property name="eclipselink.weaving" value="true"/>
    <property name="eclipselink.cache.shared.default" value="false"/>
    <property name="eclipselink.logging.level" value="FINEST"/>
  </properties>
</persistence-unit>
</persistence>

更新

我正在使用 eclipselink javaagent 字符串来启动 tomcat。还有其他 OneToOne 映射在我的项目中被延迟加载,它们会被编织。它只有这一类(EmailNotificationQueueRow)没有被编织。

【问题讨论】:

  • 如果将 JoinColumn 上的 `nullable` 或 OneToOne 上的 optional 设置为 false 会改变什么,你能试试吗?另外,您使用的是哪个版本的 EclipseLink?

标签: java tomcat jpa eclipselink


【解决方案1】:

这是在您的项目中启用dynamic weaving 的完整解决方案,它还展示了如何启用静态编织。

【讨论】:

    【解决方案2】:

    我有点困惑。您说您在 Tomcat 中使用 Java EE 应用程序?不明白,Tomcat只是一个web容器,不是Java EE服务器?

    兼容的 Java EE 服务器将允许在部署期间编织托管 JPA 实体,但 Tomcat 不是 Java EE 服务器。

    我不确定使用 -javaagent 启动 Tomcat 是否与 Tomcat 加载类的方式一致。我认为您必须在 Tomcat 中使用静态编织,或者使用 Spring。不确定您的某些课程是如何工作的?你确定它们是动态编织的吗?可能和Tomcat加载类的方式有关,它们的部署方式是一样的吗?

    【讨论】:

    • javaagent 可以在加载所有类时拦截它们,因此即使在 java se 环境中也允许动态编织。参见例如wiki.eclipse.org/…
    • 我最终使用了静态编织。奇怪的部分是动态编织正在与其他类上的 javaagent 一起使用,但没有 EmailNotificationQueueRow。使用静态编织它确实适用于所有类。仍然不确定为什么,但我会把它归结为 Tomcat 不符合 JEE。
    【解决方案3】:

    Tomcat 加载时编织呢?我认为这是最好的方法。我成功地将它与 Tomcat 6/7 一起使用。
    http://static.springsource.org/spring/docs/2.0.x/reference/orm.html#orm-jpa
    章节
    "12.6.1.3.1. Tomcat 加载时织入设置 (5.0+)"

    【讨论】:

    【解决方案4】:

    请确保您已使用 jvm 参数将 EclipseLink 代理添加到 jvm

    -javaagent:eclipselink.jar 
    

    欲了解更多信息,请查看EclipseLink documentation

    【讨论】:

    • 不幸的是我已经是了。在项目的其他地方,我有一些延迟加载的一对一映射,它们工作得很好。它只是 EmailNotificationQueueRow 实体没有被映射。我将更新我的问题以包含此信息....
    猜你喜欢
    • 2018-01-04
    • 2013-08-31
    • 2023-03-30
    • 2019-07-22
    • 2011-10-25
    • 2012-05-30
    • 1970-01-01
    • 2015-04-13
    • 1970-01-01
    相关资源
    最近更新 更多