Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6610919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:54:07+00:00 2026-05-25T19:54:07+00:00

I have a Restful web service developed in Spring MVC which currently returns farmer

  • 0

I have a Restful web service developed in Spring MVC which currently returns farmer information and allows for the deletion and addition of new farmers to the database. When extending the web service to include farmer advisors I am recieving the following error as soon as I add the transactional annotation to the advisor DAO implementation:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'advisorDAO' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: methods with same signature getAdvisors() but incompatible return types: [interface java.util.List, class [Lorg.springframework.aop.Advisor;]

The odd part about this error is that the system compiles fine and as intended prior to the annotation being added to the class, however as I need to be able to persist the entity to the database the transactions are a requirement. I know what the error means but I am at a loss as to why this is only an issue when using the annotation which isn’t even applied to the method the compiler is complaining about.

The Advisors DAO interface:

public interface AdvisorDAO {
   public List<Advisor> getAdvisors();
   public Advisor getAdvisorByPk(int id);   
   public Advisor getAdvisorByFarmerID(int id);
   public Advisor getAdvisorByAdvisorID(int id);    
   public void saveAdvisor(Advisor advisor);
   public void deleteAdvisor(Advisor advisor);
   public void updateAdvisor (Advisor advisor);
}

The interface implementation:

public class JpaAdvisorDAO implements AdvisorDAO {

@PersistenceContext
private EntityManager entityManager;

public void setEntityManager(EntityManager entityManager) {
this.entityManager = entityManager;
}

@Override
public List<Advisor> getAdvisors() {
    return entityManager.createNamedQuery("Advisor.findAll").getResultList();
}

@Override
public Advisor getAdvisorByPk(int id) {
    Query query = entityManager.createNamedQuery("Advisor.findByPK");
    query.setParameter("advisorPk", id);
    return (Advisor) query.getSingleResult();
}   

@Override
public Advisor getAdvisorByFarmerID(int id) {
    Query query = entityManager.createNamedQuery("Advisor.findByFarmerId");
    query.setParameter("farmerId", id);
    return (Advisor) query.getSingleResult();
}

@Override
public Advisor getAdvisorByAdvisorID(int id) {
    Query query = entityManager.createNamedQuery("Advisor.findByAdvisorId");
    query.setParameter("advisorId", id);
    return (Advisor) query.getSingleResult();  
}    

@Override
@Transactional
public void saveAdvisor(Advisor advisor) {
    entityManager.persist(advisor);
}

@Override
@Transactional
public void deleteAdvisor(Advisor advisor) {
    entityManager.remove(entityManager.getReference(Advisor.class, advisor.getAdvisorPk()));

}

@Override
@Transactional
public void updateAdvisor (Advisor advisor) {
    entityManager.merge(advisor);
}

The context file used:

<?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:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
      http://www.springframework.org/schema/aop 
      http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
      http://www.springframework.org/schema/context 
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/tx 
      http://www.springframework.org/schema/tx/spring-tx.xsd" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc">


<bean id="farmerDAO" class="com.test.cmsservice.persistance.JpaFarmerDAO" />
<bean id="advisorDAO" class="com.test.cmsservice.persistance.JpaAdvisorDAO" />

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="SpringRestService"/>
    <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true"/>
                <property name="generateDdl" value="false"/>
                <property name="databasePlatform" value="org.hibernate.dialect.DerbyDialect"/>
            </bean>
        </property>
</bean> 
<context:annotation-config />
  <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.apache.derby.jdbc.ClientDriver"/>
    <property name="url" value="jdbc:derby://localhost:1527/SpringDBTest"/>
    <property name="username" value="APP"/>
    <property name="password" value="app"/>
  </bean>
  <tx:annotation-driven />
  <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
    <property name="dataSource" ref="dataSource"/>
  </bean>
  <bean id="persistenceAnnotation" class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:54:09+00:00Added an answer on May 25, 2026 at 7:54 pm

    Adding the annotation can’t change the return type.

    First, you have probably imported the wrong type – Advisor is a spring class as well, so fix your imports.

    Then I suspect that you have an older version of your interface or its implementation that is loaded by the classloader. The exception message says that one of the methods returns a List<Advisor> and the other – Advisor[]. Make sure everything is cleaned and up-to-date.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have developed a RESTful web service which expects an XML string to arrive
Assume I have a RESTful web service, which holds information about an object that
I have built a Spring 3 MVC driven RESTful web service app. I use
I have a restful web service which can deal with DTOs in json format
I have a ReSTful web service which needs to parse locale-sensitive data from the
I have created a RESTful PHP web service using Lithium which contains comments, each
I have a Restful web service. Reservation room can change. Which URI is better
I have a RESTful web service which represent processes and activities. Each activity is
I have a RESTful web service that returns JSON-serialized data. It can successfully serialize
I have a very simple WCF4 Restful web service which uses WcfRestContrib to allow

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.