Java Developer Interview Question

Someone adds Transactional to a method and it does not seem to work. What are the usual reasons?

What the interviewer is probing, how to structure your answer, and a spoken example you can adapt.

Quick answer

The annotation is implemented with a proxy, so it only applies when the call comes through the bean from outside. A call from another method inside the same class bypasses the proxy entirely, which is the most common cause. Other reasons: the method is not public, the exception thrown is checked so it does not trigger a rollback by default, the bean was created outside the container, or a new transaction was needed and the propagation was left as required.

Why interviewers ask this

It is a practical Spring question with several correct answers, so it shows both depth and real debugging experience. The interviewer wants the proxy self invocation issue named first, plus the rollback rule about checked exceptions, which surprises people. Follow ups usually move to propagation, to what belongs inside a transaction, and to why long transactions holding a connection are dangerous.

How to structure your answer

  • Start with the proxy model, since it explains most failures.
  • Cover self invocation and visibility requirements.
  • State the default rollback rule and how to change it.
  • Add what should not be inside a transaction at all.

Example answer

Spoken example, first person

Nine times out of ten it is self invocation. Spring wraps the bean in a proxy, and the transaction starts when a caller goes through that proxy, so if a public method in the same class calls the annotated method directly, the call never leaves the object and no transaction begins. The fix is to move the method to another bean or inject the bean into itself, and the honest fix is usually that the boundary was in the wrong place anyway. After that I check the basics: the method should be public, the bean must be Spring managed rather than created with new, and the rollback rule catches people out because by default it only rolls back on unchecked exceptions, so a checked exception commits unless I specify rollbackFor. I also look for propagation, since work that must survive the caller's rollback needs requires new, and that takes a second connection, which matters if the pool is small. And I keep transactions short: no HTTP calls, no message publishing, no waiting on anything inside one, because holding a database connection while calling a third party is how a pool gets exhausted.

Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.

See how it works

Follow-up questions to expect

  • What does propagation requires new actually do to the connection pool?
  • Why can catching an exception inside a transaction still cause a rollback?
  • How would you publish an event only after the transaction commits?

Related java developer questions

Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.

Predict my questions

Rehearse the hard questions before they are asked

Practise with a live copilot, then walk in ready. A $29 Session Pass gets you through the interview with no subscription and no lock-in.

Get GhostPilot