簡體   English   中英

實體沒有編織。 Eclipselink 2.1 +動態編織

[英]Entity is not weaved. Eclipselink 2.1 + Dynamic Weaving

我有一個Java EE應用程序,它運行在tomcat上,帶有幾個實體類,並使用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)沒有被編織。

我有點困惑。 您說您在Tomcat中使用Java EE應用程序? 我不明白,Tomcat只是一個Web容器,而不是Java EE服務器?

兼容的Java EE服務器將允許在部署期間編織托管JPA實體,但Tomcat不是Java EE服務器。

我不確定使用-javaagent啟動Tomcat是否可以使用Tomcat加載類的方式。 我認為你必須使用Tomcat靜態編織,或者使用Spring。 不確定你是如何工作的? 你確定它們是動態編織的嗎? 可能與Tomcat如何加載類有關,它們是否以相同的方式部署?

請確保使用jvm參數將EclipseLink代理添加到jvm

-javaagent:eclipselink.jar 

有關更多信息,請查看EclipseLink文檔

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+)”

這是一個在項目中實現動態編織的完整解決方案,它還展示了如何啟用靜態編織。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM