我有一个问题,希望有人能给我一些提示。
环境:
具有两个模块的maven项目
一个模块是“模型”,具有DataNucleus 3.1、HSQLDB和Spring 3依赖项。HSQLDB 在内存中运行嵌入式,从 spring applicationContext.xml 配置
另一个模块是“网络”并且具有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;
}
}
@Entity 声明
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;
}
}