3

問題があります。うまくいけば、誰かが私にヒントを与えることができます。

環境:

  • 2 つのモジュールを含むMavenプロジェクト

  • 1 つのモジュールは「モデル」であり、DataNucleus 3.1HSQLDB、および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;
    }
}
4

2 に答える 2

2

OK、この問題の修正を見つけました。以前に投稿したように、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>

だから、これが私がそれを機能させることができる唯一の方法です、これは春のバグでしょうか?

そして、その2番目の(マイナーな)問題については、SpringのLocalContainerEntityManagerFactoryBeanを使用しているため、明らかに例外がスローされます:)

于 2012-08-17T16:23:39.877 に答える
1

これはSpringのバグではなく、単に「デバッグ」レベルのメッセージです。そのメッセージを抑制するには、ログレベルを変更します<logger name="org.springframework.orm.jpa.EntityManagerFactoryUtils" additivity="false" level="error"/>

ここで私のORMデモを参照してください:https ://github.com/gordonad/core-spring-demos/tree/master/demos/orms

于 2013-01-15T21:19:05.417 に答える