Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to mark the primary key field in a Spring Boot entity.
Spring Boot
public class User { [1] private Long id; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Entity instead of @Id for the primary key.
Forgetting to annotate the primary key field.
Using @Column or @Table which are for other purposes.
✗ Incorrect
The @Id annotation marks the field as the primary key in a Spring Boot entity.
2fill in blank
mediumComplete the code to automatically generate the primary key value.
Spring Boot
public class User { @Id [1] private Long id; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using @Column instead of @GeneratedValue for key generation.
Omitting the strategy parameter.
Using @Transient which excludes the field from persistence.
✗ Incorrect
The @GeneratedValue annotation with strategy AUTO tells Spring Boot to generate the primary key automatically.
3fill in blank
hardFix the error in the code to correctly generate the primary key using identity strategy.
Spring Boot
public class Product { @Id @GeneratedValue(strategy = [1]) private Long productId; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using AUTO instead of IDENTITY when the database requires identity strategy.
Confusing SEQUENCE with IDENTITY.
Omitting the strategy parameter.
✗ Incorrect
GenerationType.IDENTITY tells Spring Boot to use the database identity column for key generation.
4fill in blank
hardFill both blanks to define a primary key with sequence generation in a Spring Boot entity.
Spring Boot
public class Order { @Id @GeneratedValue(strategy = [1], generator = [2]) private Long orderId; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing IDENTITY with sequence generator name.
Using generator name without quotes.
Using wrong GenerationType for sequence.
✗ Incorrect
Use GenerationType.SEQUENCE for sequence strategy and specify the sequence generator name as a string.
5fill in blank
hardFill all three blanks to define a primary key with sequence generation and sequence generator annotation.
Spring Boot
public class Invoice { @Id @SequenceGenerator(name = [1], sequenceName = [2], allocationSize = 1) @GeneratedValue(strategy = [3], generator = [1]) private Long invoiceId; }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different names for generator and sequence generator.
Using IDENTITY strategy with sequence generator.
Omitting quotes around string names.
✗ Incorrect
The sequence generator name is "invoice_seq", the sequence name is "seq_invoice", and the strategy is GenerationType.SEQUENCE.