問題があります。うまくいけば、誰かが私にヒントを与えることができます。
環境:
2 つのモジュールを含むMavenプロジェクト
1 つのモジュールは「モデル」であり、DataNucleus 3.1、HSQLDB、およびSpring 3の依存関係があります。HSQLDB は、Spring applicationContext.xml から構成されたメモリ内に埋め込まれて実行されます
もう 1 つのモジュールは「web」であり、GWT 依存関係があります
アプリケーションは、Spring Roo で生成されたコードをベースとして構築され、後で変更および拡張されます。
問題は、アプリを起動してデータを読み込もうとすると、例外が発生することです。
Class Document for query has not been resolved. Check the query and any imports specification; nested exception is javax.persistence.PersistenceException: Class Document for query has not been resolved. Check the query and any imports specification
最も奇妙なことは、roo によって生成されたアプリケーションのサンプルがベースとして使用され、依存関係がまったく同じであることですが、この症状がなくても、異なるモジュール化が魅力のように機能するため、今は困惑しています...置き換えようとしたことにも注意してくださいクエリで明示的な修飾子「com.myvdm.server.domain.Document」を持つ「ドキュメント」、肯定的な結果なし:
return entityManager().createQuery("SELECT COUNT(o) FROM Document o", Long.class).getSingleResult();
別のことですが、関係ないかもしれませんが、すべてのリクエストで、この例外がスローされます。
DEBUG org.springframework.orm.jpa.EntityManagerFactoryUtils - Unexpected exception on closing JPA EntityManager [INFO] java.lang.IllegalStateException: EntityManager is managed by a container (JEE) and so cannot be closed by calling the EM.close() method. Please read JPA2 spec 3.1.1 for the close() method.
最後の例外は、DataNucleus によってスローされます。私は Java EE コンテナーではなく GWT 開発モードで実行しているので、これも紛らわしいです。
ドキュメント エンティティは次のとおりです。
@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class Document {
@NotNull
private String name;
@ManyToOne
private DocumentType type;
@OneToMany(fetch = FetchType.EAGER,
cascade = CascadeType.ALL)
private Set<Field> fields;
}
アノテーション @RooJpaActiveRecord は EntityManager 操作を追加しますが、これらは別のファイルで宣言されます - ITD (型間宣言)
何か提案はありますか?よろしくお願いします。
- - - - - - 編集 - - - - - - -
privileged aspect Document_Roo_Jpa_ActiveRecord {
@PersistenceContext
transient EntityManager Document.entityManager;
public static final EntityManager Document.entityManager() {
EntityManager em = new Document().entityManager;
if (em == null) throw new IllegalStateException("Entity manager has not been injected (is the Spring Aspects JAR configured as an AJC/AJDT aspects library?)");
return em;
}
public static long Document.countDocuments() {
return entityManager().createQuery("SELECT COUNT(o) FROM Document o", Long.class).getSingleResult();
}
public static List<Document> Document.findAllDocuments() {
return entityManager().createQuery("SELECT o FROM Document o", Document.class).getResultList();
}
public static Document Document.findDocument(Long id) {
if (id == null) return null;
return entityManager().find(Document.class, id);
}
public static List<Document> Document.findDocumentEntries(int firstResult, int maxResults) {
return entityManager().createQuery("SELECT o FROM Document o", Document.class).setFirstResult(firstResult).setMaxResults(maxResults).getResultList();
}
@Transactional
public void Document.persist() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.persist(this);
}
@Transactional
public void Document.remove() {
if (this.entityManager == null) this.entityManager = entityManager();
if (this.entityManager.contains(this)) {
this.entityManager.remove(this);
} else {
Document attached = Document.findDocument(this.id);
this.entityManager.remove(attached);
}
}
@Transactional
public void Document.flush() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.flush();
}
@Transactional
public void Document.clear() {
if (this.entityManager == null) this.entityManager = entityManager();
this.entityManager.clear();
}
@Transactional
public Document Document.merge() {
if (this.entityManager == null) this.entityManager = entityManager();
Document merged = this.entityManager.merge(this);
this.entityManager.flush();
return merged;
}
}
@エンティティ宣言
privileged aspect Document_Roo_Jpa_Entity {
declare @type: Document: @Entity;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long Document.id;
@Version
@Column(name = "version")
private Integer Document.version;
public Long Document.getId() {
return this.id;
}
public void Document.setId(Long id) {
this.id = id;
}
public Integer Document.getVersion() {
return this.version;
}
public void Document.setVersion(Integer version) {
this.version = version;
}
}