我确实有一个应用程序,我正在尝试为cassandra创建LocalContainerEntityManagerFactoryBean ...我也有很少的实体由hibernate映射和管理,不应该从这个EMF中扫描...
我在LocalContainerEntityManagerFactoryBean中添加了pakagesToScan属性,但它仍在尝试扫描所有包...
My 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>
My 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的通配符。*但dint help ...
我正在使用spring 4.1.1 ....
提前致谢...
答案 0 :(得分:0)
堆栈跟踪显示Application
对象(我假设它是一个Hibernate POJO)必须具有注释为@Id
的属性。此字段很重要,因为它表示将用于数据存储中的对象查找的键属性。
以下示例代码与Kundera展示了此示例。 https://code.google.com/p/kundera/wiki/HowToUseKunderaWithSpring