gpt4 book ai didi

spring - DataNucleus: Class ... for query 尚未解决。检查查询和任何导入规范

转载 作者:行者123 更新时间:2023-12-04 04:22:36 25 4
gpt4 key购买 nike

我有一个问题,希望有人能给我一些提示。
环境:

  • 行家 合作的项目两个模块
  • 一个模块是'型号 ',并且有 数据核 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;
    }
    }

    最佳答案

    好的,我找到了解决此问题的方法。
    正如我之前发布的,使用 Spring 的 applicationContext.xml 和 persistence.xml 文件作为基本配置,我无法让它工作。我删除了persistence.xml,而是使用了这个配置(请注意packagesToScan属性的使用和传递DataNucleus属性——基本上所有传统上在persistence.xml中的信息):

     <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" 
    id="entityManagerFactory">
    <property name="persistenceUnitName" value="persistenceUnit"/>
    <property name="packagesToScan" value="com.myvdm.server.domain"/>
    <property name="persistenceProviderClass" value="org.datanucleus.api.jpa.PersistenceProviderImpl"/>
    <property name="jpaPropertyMap">
    <map>
    <entry key="datanucleus.ConnectionDriverName" value="org.hsqldb.jdbc.JDBCDriver"/>
    <entry key="datanucleus.storeManagerType" value="rdbms"/>
    <entry key="datanucleus.ConnectionURL" value="jdbc:hsqldb:mem:myvdm"/>
    <entry key="datanucleus.ConnectionUserName" value="sa"/>
    <entry key="datanucleus.ConnectionPassword" value=""/>
    <entry key="datanucleus.autoCreateSchema" value="true"/>
    <entry key="datanucleus.autoCreateTables" value="true"/>
    <entry key="datanucleus.autoCreateColumns" value="false"/>
    <entry key="datanucleus.autoCreateConstraints" value="false"/>
    <entry key="datanucleus.validateTables" value="false"/>
    <entry key="datanucleus.validateConstraints" value="false"/>
    <entry key="datanucleus.jpa.addClassTransformer" value="false"/>
    </map>
    </property>
    <property name="dataSource" ref="dataSource"/>
    </bean>

    所以这是我让它工作的唯一方法,这可能是一个 Spring 错误吗?

    关于第二个(次要)问题,显然会抛出异常,因为我使用的是 Spring 的 LocalContainerEntityManagerFactoryBean :)

    关于spring - DataNucleus: Class ... for query 尚未解决。检查查询和任何导入规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11925449/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com