packagesToScan property in LocalContainerEntityManagerFactoryBean not working

3.1k Views Asked by At

HI I do have a application where I am trying to create LocalContainerEntityManagerFactoryBean for cassandra... I also have few entities which are mapped and managed by hibernate and that should not be scanned from this EMF...

I have added pakagesToScan property in the LocalContainerEntityManagerFactoryBean but still it is trying to scan all packages...

My Spring xml is as follows...

<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 is as follows

<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>

The error I am getting is as follows:

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)

I am not able to resolve this.. I tries wildcard with the package name org.amaze.db.usage.objects.* but dint help...

I am using spring 4.1.1....

Thanks in advance...

1

There are 1 best solutions below

1
On

The stacktrace shows that the Application object (I assume it's a Hibernate POJO) must have a property with an annotation of @Id. This field is important as it signifies the key property that will be used for the object lookup in the data store.

The following sample code with Kundera shows this example. https://code.google.com/p/kundera/wiki/HowToUseKunderaWithSpring