1

嗨,我确实有一个应用程序,我正在尝试为 cassandra 创建 LocalContainerEntityManagerFactoryBean ...

我在 LocalContainerEntityManagerFactoryBean 中添加了 pakagesToScan 属性,但它仍在尝试扫描所有包...

我的 Spring xml 如下...

<bean id="cassandraEmf"
        class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="cassandra" />
        <property name="loadTimeWeaver">
            <bean
                class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
        </property>
        <property name="packagesToScan">
            <array value-type="java.lang.String">
                <value>org.amaze.db.usage.objects</value>
            </array>
        </property>
    </bean>

我的 Persistence.xml 如下

<persistence-unit name="cassandra">
    <provider>com.impetus.kundera.KunderaPersistence</provider>
        <properties>
            <property name="kundera.nodes" value="localhost"/>
            <property name="kundera.port" value="9160"/>
            <property name="kundera.keyspace" value="amaze"/>
            <property name="kundera.dialect" value="cassandra"/>
            <property name="kundera.client.lookup.class" value="com.impetus.client.cassandra.pelops.PelopsClientFactory" />
            <property name="kundera.cache.provider.class" value="com.impetus.kundera.cache.ehcache.EhCacheProvider"/>
            <property name="kundera.cache.config.resource" value="/ehcache-test.xml"/>
            <property name="packagesToScan" value="org.amaze.db.usage.objects" />
        </properties>
    </persistence-unit>

我得到的错误如下:

Caused by: com.impetus.kundera.metadata.validator.InvalidEntityDefinitionException: Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraEmf' defined in class path resource [dbusage.xml]: Invocation of init method failed; nested exception is com.impetus.kundera.metadata.validator.InvalidEntityDefinitionException: org.amaze.db.hibernate.objects.Application must have an @Id field.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at org.amaze.db.KunderaTest.main(KunderaTest.java:14)
Caused by: com.impetus.kundera.metadata.validator.InvalidEntityDefinitionException: org.amaze.db.hibernate.objects.Application must have an @Id field.
    at com.impetus.kundera.metadata.processor.TableProcessor.validateIdAttribute(TableProcessor.java:415)
    at com.impetus.kundera.metadata.processor.TableProcessor.validateAndSetId(TableProcessor.java:405)
    at com.impetus.kundera.metadata.processor.TableProcessor.populateMetadata(TableProcessor.java:155)
    at com.impetus.kundera.metadata.processor.TableProcessor.process(TableProcessor.java:90)
    at com.impetus.kundera.metadata.MetadataBuilder.buildEntityMetadata(MetadataBuilder.java:132)
    at com.impetus.kundera.configure.MetamodelConfiguration.scanClassAndPutMetadata(MetamodelConfiguration.java:398)
    at com.impetus.kundera.configure.MetamodelConfiguration.loadEntityMetadata(MetamodelConfiguration.java:232)
    at com.impetus.kundera.configure.MetamodelConfiguration.configure(MetamodelConfiguration.java:103)
    at com.impetus.kundera.configure.Configurator.configure(Configurator.java:65)
    at com.impetus.kundera.KunderaPersistence.initializeKundera(KunderaPersistence.java:109)
    at com.impetus.kundera.KunderaPersistence.createEntityManagerFactory(KunderaPersistence.java:81)
    at com.impetus.kundera.KunderaPersistence.createContainerEntityManagerFactory(KunderaPersistence.java:65)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:341)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627)

我无法解决这个问题..我尝试使用包名 org.amaze.db.usage.objects.* 的通配符,但帮助...

我正在使用弹簧 4.1.1 ....

提前致谢...

4

1 回答 1

0

堆栈跟踪显示该Application对象(我假设它是一个 Hibernate POJO)必须具有一个带有注释的属性@Id。该字段很重要,因为它表示将用于在数据存储中查找对象的关键属性。

以下带有昆德拉的示例代码显示了此示例。https://code.google.com/p/kundera/wiki/HowToUseKunderaWithSpring

于 2014-12-05T09:36:43.033 回答