Scrivio Interview library
DebuggingFoundations6 min read · updated 12 November 2026

Read this stack trace and say where the bug is and how you would find the root cause: com.acme.ServiceException: Failed to load order 42 at OrderService.load(OrderService.java:57) ... Caused by: org.hibernate.exception.SQLGrammarException ... Caused by: org.postgresql.util.PSQLException: ERROR: column o.status_code does not exist

The root cause is the last Caused by line: PostgreSQL rejected the SQL because the column o.status_code does not exist. OrderService line 57 is only where the failure was caught and wrapped into a ServiceException, so it gives context but is not the bug. A missing column usually means the entity mapping and the database schema disagree, for example a migration that has not run on this database or a field mapped to the wrong column name, so we check the schema version and either run the migration or fix the @Column mapping.

Why this question is asked

Reading a stack trace quickly is one of the most practical skills an engineer has, and in an incident it decides whether we find the cause in two minutes or two hours. Interviewers give a trace like this because the top line points confidently at our own service, while the real answer sits at the bottom, two libraries away. In this answer, we will recap how exceptions are chained, read this trace from the bottom up, explain what the ... 12 more lines mean, work out why the column is missing, and go through how to fix it and stop it from happening again.

1A Quick Recap of Exception Chaining

When one layer catches an exception and throws a new one, good code passes the original as the cause: new ServiceException("Failed to load order 42", e). The new exception carries the old one inside it, and the old one may carry another. When the trace is printed, Java prints the outermost exception first, then each cause under a Caused by: heading, all the way down to the original problem.

So a printed trace is a chain read from the outside in. The first line is the last thing that happened, and the last Caused by is the first thing that went wrong.

Step throughThe chain in this trace, outermost first
  1. com.acme.ServiceExceptionFailed to load order 42, thrown at OrderService.java:57
  2. org.hibernate.exception.SQLGrammarExceptionHibernate translated the JDBC error
  3. org.postgresql.util.PSQLExceptionERROR: column o.status_code does not exist; the root cause

3 layers, from the top down. Step through them one at a time.

Each layer wrapped the one below it. The bottom layer is where things actually went wrong.

2Reading the Trace From the Bottom

Here is a fuller version of the trace, shortened to the interesting lines.

Text
com.acme.ServiceException: Failed to load order 42
at com.acme.OrderService.load(OrderService.java:57)
at com.acme.OrderController.get(OrderController.java:31)
...
Caused by: org.hibernate.exception.SQLGrammarException: JDBC exception executing SQL
[select o.id, o.status_code, ... from orders o where o.id=?]
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(...)
... 12 more
Caused by: org.postgresql.util.PSQLException: ERROR: column o.status_code does not exist
Position: 15
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(...)
... 12 more

We start at the last Caused by. PostgreSQL itself says the column o.status_code does not exist. That is a fact about the database, not a guess. Moving up, Hibernate's SQLGrammarException shows the exact SQL it generated, which tells us the query came from an entity mapping rather than hand-written SQL. Only then do we look at the top: OrderService.load at line 57 caught the Hibernate exception and wrapped it. That line tells us which use case failed and for which order, which is useful context, but nothing on line 57 is wrong.

Notice that the exact SQL is a gift. With it we can run the same query in psql against the same database and see the error ourselves, which removes any doubt about which database and schema the service is talking to.

3What the ... 12 more Lines Mean

Each exception in the chain has its own stack trace, and the inner ones are usually almost identical to the outer one at the bottom, because they were thrown from deeper inside the same call. Printing those shared frames three times would only add noise. So Java prints the frames that differ, then writes ... 12 more to say that the remaining 12 frames are the same as the last 12 frames of the enclosing exception's trace, which is already printed above.

So nothing is lost. If we need the full path of the inner exception, we take the frames shown and continue with the matching frames of the trace above it.

4Why the Column Is Missing

Hibernate builds the SQL from the entity. If the Order entity has a field statusCode, Spring Boot's default naming strategy maps it to the column status_code. PostgreSQL says that column is not in the orders table of this database. So the entity and the schema disagree, and there are only a few ways that happens.

Java
@Entity
@Table(name = "orders")
class Order {
@Id Long id;
String statusCode; // Spring Boot's default naming -> column status_code
}
-- In psql on the failing database
\d orders
-- id | bigint
-- status | varchar(20) -- the column is still called status here

The most common cause is a migration that added or renamed the column and has not run on this environment: the code was deployed, but the Flyway or Liquibase script failed, was skipped, or targeted another database. The second is a mapping mistake: the column was always called status, and someone renamed the field without adding @Column(name = "status"). A third is that the service points at the wrong database or schema, for example a staging URL in a production profile.

5Fixing It and Preventing It

First we check which migrations have run. Flyway keeps its history in the flyway_schema_history table, and Liquibase in DATABASECHANGELOG. If the migration that renames the column is missing or failed, we fix and run it. If the schema is right and the mapping is wrong, we correct the field or add @Column with the real column name.

SQL
SELECT version, description, success FROM flyway_schema_history ORDER BY installed_rank DESC LIMIT 3;
-- 41 | rename status to status_code | f -- failed, so the column was never renamed
// Or, when the schema is right and the mapping is wrong:
@Column(name = "status")
String statusCode;
Step throughFrom stack trace to fix
  1. Read the last Caused bycolumn o.status_code does not exist
  2. Read the generated SQLquery comes from the Order entity
  3. Does the column exist under another name?
    YesCheck migration historyNoCheck the database URL and schema
  4. Migration missing or failed?
    YesFix and run the migrationNoFix the @Column mapping
  5. Add ddl-auto=validatemismatches fail at startup next time

5 steps in order. Play them, or step through them one at a time.

To catch this earlier next time, we can set spring.jpa.hibernate.ddl-auto=validate, which makes Hibernate compare the mappings with the schema at startup and fail the deployment instead of the first request. Running migrations as a required step of the deployment, and failing the rollout when one fails, closes the gap from the other side.

6Follow-up questions

Why read the bottom first rather than the top?

Because the top is where the failure was last caught and rethrown, while the last Caused by is where it started. Each wrapper adds context such as which order or which use case, but only the root cause says what actually went wrong. Reading bottom-up, then using the upper layers for context, is the fastest route.

What if the trace has no Caused by at all, but we know there should be one?

Then some layer threw a new exception without passing the original as the cause, for example throw new ServiceException(e.getMessage()). The root cause's trace is lost. The fix is in the code: always pass the caught exception as the cause when wrapping.

Could this be a permissions problem rather than a missing column?

A permissions problem gives a different PostgreSQL error, such as permission denied for table orders. column does not exist really means the column is not visible in the table PostgreSQL resolved, which is why it is also worth checking the search_path and schema the connection uses.

7Conclusion

In this answer, we read the trace from the bottom up. The last Caused by, PostgreSQL's column o.status_code does not exist, is the root cause; Hibernate's SQLGrammarException showed the generated SQL; and OrderService line 57 was only where the failure was wrapped. The ... 12 more lines are frames shared with the enclosing trace. A missing column means the entity mapping and the schema disagree, so we checked the migration history, ran the missing migration or fixed the @Column name, and added ddl-auto=validate so such mismatches fail at startup.

What to say in the interviewAbout 90 seconds aloud

Open with

I read a chained trace from the bottom. The last Caused by is the root cause, and here it is PostgreSQL saying column o.status_code does not exist. Above it, Hibernate's SQLGrammarException tells me the failing SQL was generated from an entity mapping, and it usually prints the query, so I can run it myself.

Then, if they want more

The top, OrderService line 57, is just where the exception was caught and wrapped into a ServiceException. It is useful context, it tells me which use case and which order, but the bug is not on that line.

The ... 12 more lines simply mean those frames are identical to the enclosing exception's trace, so Java does not print them again. A missing column means the entity and the schema disagree.

Most often a migration that added or renamed the column has not run or failed on this environment, so I would check flyway_schema_history or Liquibase's changelog table and run or fix it.

If the schema is right, then the mapping is wrong, for example the field statusCode maps to status_code by default while the real column is status, and I would add @Column with the right name. I would also confirm the service is pointing at the right database and schema.

To prevent it, I would set ddl-auto to validate so Hibernate checks mappings at startup, and make failed migrations fail the deployment.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Read this stack trace and say where the bug is and how you would find the root cause...": https://scrivio-interview-library.netlify.app/java/exceptions/bb89eb704a/