Explore Courses Blog Tutorials Interview Questions
0 votes
in Java by (3.9k points)

I thought hibernate takes into consideration only class variables that are annotated with @Column. But strangely today when I added a variable (that is not mapped to any column, just a variable i need in the class), it is trying to include that variable in the select statement as a column name and throws the error -

Unknown column 'team1_.agencyName' in 'field list'

My class -



public class Team extends BaseObject implements Serializable {

@Id  @GeneratedValue(strategy=GenerationType.AUTO)

private Long id;


private String name;


private String code;

@Column(name = "agency_id")

private Long agencyId;

private String agencyName; //note: not annotated.


1 Answer

0 votes
by (46k points)

JPA will use all properties of the class, unless you specifically mark them with @Transient:


private String agencyName;

The @Column annotation is purely optional, and is there to let you override the auto-generated column name. Furthermore, the length attribute of @Column is only used when auto-generating table definitions, it has no effect on the runtime.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 14, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
asked Jul 22, 2019 in Java by Anvi (10.2k points)

Browse Categories