0
0
Spring Bootframework~20 mins

Column mapping with @Column in Spring Boot - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Column Mapping Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the effect of @Column(name = "user_email") on a field?

Consider a Spring Boot entity with a field annotated as @Column(name = "user_email"). What does this annotation do?

Spring Boot
public class User {
  @Column(name = "user_email")
  private String email;
}
AMaps the field 'email' to the database column named 'user_email'.
BRenames the Java field 'email' to 'user_email' in the code.
CCreates a new database column 'email' and ignores 'user_email'.
DAutomatically converts the field value to uppercase before saving.
Attempts:
2 left
💡 Hint

Think about how Java fields connect to database columns.

📝 Syntax
intermediate
2:00remaining
Identify the correct @Column usage to set a column as non-nullable

Which option correctly uses @Column to make a database column NOT NULL?

Spring Boot
public class Product {
  @Column(??? )
  private String name;
}
A@Column(notNull = true)
B@Column(nullable = false)
C@Column(nullable = true)
D@Column(required = true)
Attempts:
2 left
💡 Hint

Check the exact attribute name for nullability in @Column.

🔧 Debug
advanced
2:00remaining
Why does this @Column annotation cause a runtime error?

Given the entity field below, why will the application fail at runtime?

Spring Boot
public class Order {
  @Column(name = "order_date", length = 10)
  private LocalDate date;
}
AThe 'length' attribute is invalid for LocalDate type causing a runtime error.
BThe 'name' attribute must be omitted for LocalDate fields.
CThe field 'date' must be public for @Column to work.
DLocalDate fields cannot be annotated with @Column.
Attempts:
2 left
💡 Hint

Consider which @Column attributes apply to which data types.

state_output
advanced
2:00remaining
What is the database column name for this field?

Given the entity below, what is the exact database column name for the field userName?

Spring Boot
public class Account {
  @Column(name = "user_name")
  private String userName;
}
AUSER_NAME
Busername
Cuser_name
DuserName
Attempts:
2 left
💡 Hint

Look at the name attribute inside @Column.

🧠 Conceptual
expert
2:00remaining
What happens if @Column is omitted on a field?

In a Spring Boot JPA entity, if a field has no @Column annotation, what is the default behavior for database column mapping?

Spring Boot
public class Customer {
  private String address;
}
AThe field is ignored and not mapped to any database column.
BThe application throws an error because @Column is mandatory.
CThe field is mapped to a column named 'column_address' automatically.
DThe field is mapped to a column with the same name as the field, using default settings.
Attempts:
2 left
💡 Hint

Think about default JPA mapping conventions.