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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:28:52+00:00 2026-05-28T19:28:52+00:00

I am trying to implement method described here , but can’t make it work.

  • 0

I am trying to implement method described here, but can’t make it work.

There are no errors during compilation, but the interceptor never fired.

DAO:

public class GeneralInvoicesDAO {
@Autowired
private SessionFactory sessionFactory;

@Autowired
private Interceptor entityInterceptor;

   @Transactional
   public void update(GeneralInvoice object) {
      Session session = SessionFactoryUtils.getSession(sessionFactory, entityInterceptor, null);

      session.saveOrUpdate(object);
   }
}

The intercepter class:

public class NewEntityInterceptor extends EmptyInterceptor implements Interceptor {
    /**
     * 
     */
    private static final long serialVersionUID = 2914362528125673753L;

    @Override
    public Boolean isTransient(Object n) {
         Logger logger = Logger.getLogger(getClass().getName());

         try {
             logger.warn("test");
             Boolean result = Boolean.FALSE;

             BaseEntity entity = (BaseEntity) n;
             if (entity.getId() <= 0L) {
                 entity.setId(null); 
                 result = Boolean.TRUE;
             }
             logger.warn(result.toString());
             return result;
        }
        catch (Exception e) {
            e.printStackTrace();
            return super.isTransient(n);
        }
     }
}

Config:

<bean id="newEntityInterceptor" class="de.crm.interceptor.NewEntityInterceptor" />
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
        <property name="entityInterceptor" ref="newEntityInterceptor" />
    </bean>

What’s wrong?
Thank you

  • 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-28T19:28:54+00:00Added an answer on May 28, 2026 at 7:28 pm

    Few observations from you code

    1. You are NOT overriding any of the methods in EmptyInterceptor. Check out this link with a sample interceptor example.

    2. EmptyInterceptor provides the default implementations of an entity life cycle events which you can intercept. You need to override the method of your interest.

    3. I am not sure if transactionManager needs any reference to the interceptor. Its purely a hibernate thing. You can do away with it. Interceptors are needed either with session or session factory (you are using session level interceptor).

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

Sidebar

Related Questions

I am trying to implement left array rotation using the method described here: http://www.cs.bell-labs.com/cm/cs/pearls/s02b.pdf
im trying to implement a getBounds() method, but i cant get union to work;
I'm trying to implement a website screen shot class as described here http://www.plentyofcode.com/2007/09/website-screenshot-capture-with-aspnet.html The
I'm trying to implement method Find that searches the database. I forgot to mention
So I'm trying to implement the alterTime method from the EaseActionsTest example from the
I am trying to implement my own authentication method for AuthKit and am trying
I'm trying to implement a class in C# with a method that intercepts the
I would like to implement the method User.calculate_hashed_password . I'm trying to use the
Currently I'm trying to implement Transaction Script pattern (Exactly how Martin Fowler described by
I'm trying to implement method chaining in C++, which turns out to be quite

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.