Home > Software engineering >  Spring Data entity column property is always null when reading from the database
Spring Data entity column property is always null when reading from the database

Time:03-09

On an existing DB table I've added a column and in the JPA entity I've added a property as well. I've initialized the new db column with default values.

ALTER TABLE MYTABLE ADD NEW_COLUMN VARCHAR2(4000 CHAR);
UPDATE MYTABLE SET NEW_COLUMN = 'AAA';
@Column(name = "NEW_COLUMN", nullable = false)
private String newColumn;
 
@Query(value = "select * from mytable ", nativeQuery = true)

The query returns all the rows in the table, but the field newColumn is always null, the other fields are populated correctly. When I do the same query on the command line, the values for the column are there.

What could be the reason that JPA returns null values for that new column?

CodePudding user response:

I found the reason why JPA return null for that new column. In SQL developer, I initialized the new DB column with value "AAA", but I didn't commit after the SQL finished the update. After I did a commit in SQL Developer, the JPA query returned the value "AAA"

  • Related