Fryder
Fryder

Reputation: 423

spring open jpa db2 error

My spring jpa poc is failing to get repository injected. Throwing an exception

java.lang.IllegalArgumentException: Interface must be annotated with @org.springframework.data.repository.RepositoryDefinition!

I am giving all my soruce code so that it can be identified by some one who went through this

my app-context xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:jdbc="http://www.springframework.org/schema/jdbc"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:jpa="http://www.springframework.org/schema/data/jpa"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
       http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd">


 <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
            p:persistenceUnitName="POC"
            p:packagesToScan="com.poc.accountant.orm"   
            p:dataSource-ref="dataSource"
            p:jpaVendorAdapter-ref="openJpaVendor" />


<!--        p:persistenceXmlLocation="classpath*:persistence.xml" -->

<bean id="openJpaVendor" class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
    <property name="showSql" value="true"/>
    <property name="databasePlatform" value="org.apache.openjpa.jdbc.sql.DB2Dictionary" />
    </bean>
<bean id="jpaDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/tepds"/>
</bean>

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/tepds"
    resource-ref="true" cache="true" />
<!--  <context:component-scan base-package="com.poc.accountant.orm"/> -->
<!--  <context:component-scan base-package="com.poc.accountant.reposotories" /> -->

 <jpa:repositories base-package="com.poc.accountant.reposotories"/>
</beans>

my Entity class

package com.poc.accountant.orm;

import java.io.Serializable;
import java.util.Date;
    import javax.persistence.Table;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * @author Fryder
 * 
 */
@Entity
    @Table(name = "POC.PUSHAPPS")
public class PushApps implements Serializable {

    /**
     * generated serial version ID
     */
    private static final long serialVersionUID = -6763892550710204820L;

    @Id
    @Column(name = "appid")
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long appid;

    @Column(name = "msgid")
    private String msgid;

    @Column(name = "severity")
    private String severity;

    @Column(name = "application")
    private String application;

    @Column(name = "source")
    private String source;

    @Column(name = "component")
    private String component;

    @Column(name = "enabled")
    private Boolean enabled;

    @Column(name = "appgroup")
    private Long appgroup;

    @Column(name = "last_err")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastErr;

    @Column(name = "last_err_sent")
    @Temporal(TemporalType.TIMESTAMP)
    private Date lastErrSent;

    //getters and setters stripped

}

My repository class

package com.poc.accountant.reposotories;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.data.jpa.repository.JpaRepository;

import com.poc.accountant.orm.PushApps;

/**
 * @author Fryder
 *
 */
public interface PushAppsRepository extends JpaRepository<PushApps, Long> {

    List<PushApps> findByAppId(long appId);

}

My error log

7  poc  WARN   [[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.Runtime - An error occurred while registering a ClassTransformer with PersistenceUnitInfo: name 'poc', root URL [file:/C:/Development/Src code and Artifacts/accountant-parent/accountant-web/target/classes/]. The error has been consumed. To see it, set your openjpa.Runtime log level to TRACE. Load-time class transformation will not be available.
10  poc  INFO   [[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.Runtime - OpenJPA dynamically loaded a validation provider.
167  poc  INFO   [[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.Runtime - Starting OpenJPA 2.0.1
641  poc  TRACE  [[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t 8564204, conn 499> executing stmnt 502 SELECT CURRENT SCHEMA FROM SYSIBM.SYSDUMMY1
651  poc  TRACE  [[ACTIVE] ExecuteThread: '8' for queue: 'weblogic.kernel.Default (self-tuning)'] openjpa.jdbc.SQL - <t 8564204, conn 499> [10 ms] spent
<May 2, 2014 10:12:41 AM EDT> <Warning> <HTTP> <BEA-101162> <User defined listener org.springframework.web.context.ContextLoaderListener failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pushAppsRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Interface must be annotated with @org.springframework.data.repository.RepositoryDefinition!.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pushAppsRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Interface must be annotated with @org.springframework.data.repository.RepositoryDefinition!
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
    Truncated. see log file for complete stacktrace
Caused By: java.lang.IllegalArgumentException: Interface must be annotated with @org.springframework.data.repository.RepositoryDefinition!
    at org.springframework.util.Assert.isTrue(Assert.java:65)
    at org.springframework.data.repository.core.support.AnnotationRepositoryMetadata.<init>(AnnotationRepositoryMetadata.java:48)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepositoryMetadata(RepositoryFactorySupport.java:173)
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:207)
    at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:84)
    Truncated. see log file for complete stacktrace

Upvotes: 1

Views: 1149

Answers (2)

Oliver Drotbohm
Oliver Drotbohm

Reputation: 83171

Are you sure the stack trace is referring to the PushAppsRepository you showed above? The exception should only be thrown if we find a repository interface that's not extending Spring Data's Repository by some means (the one you show clearly does).

It might be helpful to debug into RepositoryFactorySupport.getRepositoryMetadata(…) and have a look why the assignment check fails there.

Upvotes: 1

Alan Hay
Alan Hay

Reputation: 23246

The interface definition is as below:

public interface PushAppsRepository extends JpaRepository<PushApps, Long> {

    List<PushApps> findByAppId(long appId);

}

However the property in your Entity is 'appid'. I am guessing the scanner will be unable to resolve this query and will then be expecting some kind of implementation.

Change 'appid' to appId. Or better still remove it competely. Your interface will inherit a method findOne() or getOne() from JPARepository which you can use to retrieve an Entity by PK.

Upvotes: 0

Related Questions