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 9247947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:51:48+00:00 2026-06-18T09:51:48+00:00

I am implementing Spring old declarative TX technique Here is my Target DAO Object:

  • 0

I am implementing Spring old declarative TX technique

Here is my Target DAO Object:

neccesary imports..

public class UserDAOImpl extends JdbcDaoSupport {   
public void add(int id, String name, Float salary){
    System.out.println("add");
    String SQL = "insert into User_Details (id, name, salary) values (?, ?, ?)";
    getJdbcTemplate().update(SQL, id, name, salary);
    getJdbcTemplate().update(SQL, id, name, salary);
    getJdbcTemplate().update(SQL, id, name, salary);
    throw new java.lang.RuntimeException("Exception occurs :)");
}

}

applicationContext.xml:

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>

<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
    <property name="transactionManager" ref="transactionManager" />
    <property name="transactionAttributes">
        <props>
            <prop key="add">PROPAGATION_REQUIRED</prop>
        </props>
    </property>
</bean>

<bean id="userDetailProxy" class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="target" ref="userDetailDAOImpl" />
    <property name="interceptorNames">
        <list>
            <value>transactionInterceptor</value>
        </list>
    </property>
</bean>
<bean id="userDetailDAOImpl" class="com.gagan.dao.UserDAOImpl">
  <property name="dataSource"  ref="dataSource" />    

Main Class:

imports..

public class SpringTxTestCase {

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

    UserDAOImpl ud=(UserDAOImpl)context.getBean("userDetailProxy");
    ud.add(101,"Rahul", 1233.6f);
}

}

When i execute my Application i got this error:

Exception in thread “main” java.lang.ClassCastException: $Proxy0 cannot be cast to com.gagan.dao.UserDAOImpl
at SpringTxTestCase.main(SpringTxTestCase.java:14)

I have properly configured org.springframework.aop.framework.ProxyFactoryBean pointing to my com.gagan.dao.UserDAOImpl in applicationContext.xml but i am confused why i got ClassCastException error.

Thanks in advance,
Gagan

  • 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-06-18T09:51:49+00:00Added an answer on June 18, 2026 at 9:51 am

    Using Spring to proxy your DAO impl class doesn’t yield an instance of the impl class. It yields something that implements the same interfaces as that class. Therefore you can never cast it to the impl class, only to the interfaces. That’s because Spring uses JDK dynamic proxies under the hood (by default). Since you don’t actually have a DAO interface, your proxy is pretty much useless to you. Add an interface to the DAO and refer to it via the interface.

    Update: Oh, I should also note that the DAO is almost never the right place for transaction boundaries. They belong in your “service” layer except in a few, rare cases because a transaction reflects a unit of business work, not a unit of persistence work.

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

Sidebar

Related Questions

I'm playing around with implementing Spring AOP programmatically. I created a simple factory class
I'm using hibernate validator framework with Spring. A class implementing the Spring Validator validates
I have a spring batch program where I am implementing skiplistener class as below:
Implementing a simple Login screen using JSF and Spring and Hibernate. I have written
While implementing some security aspects with Spring Security, I have noticed that both Authentication
Trying to understand what's the correct way of implementing OpenID authentication with Spring Security.
I have a j2ee application running on spring framework. I am implementing a transaction
I'm implementing a TryParse(string s, Out object result) method. If the parse fails, I
Implementing a custom Dependency Property on a Framework Element object causes my Visual Studio
I'm working on converting an old Struts 1.x application to Spring MVC and in

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.