Add Product entity for catalog
Problem Context
We need a Product entity that will be stored in HashSets and used as HashMap keys for the shopping cart feature.
Intermediate
100 points
File Changes (1)
src/main/java/com/example/entity/Product.java
ADDED
@@ -0 +1 @@
| 1 | +package com.example.entity; |
|
| 2 | + |
|
| 3 | +import jakarta.persistence.*; |
|
| 4 | +import java.math.BigDecimal; |
|
| 5 | +import java.util.Objects; |
|
| 6 | + |
|
| 7 | +@Entity |
|
| 8 | +public class Product { |
|
| 9 | + |
|
| 10 | + @Id |
|
| 11 | + @GeneratedValue(strategy = GenerationType.IDENTITY) |
|
| 12 | + private Long id; |
|
| 13 | + |
|
| 14 | + private String name; |
|
| 15 | + private BigDecimal price; |
|
| 16 | + private String sku; |
|
| 17 | + |
|
| 18 | + // Getters and setters... |
|
| 19 | + |
|
| 20 | + @Override |
|
| 21 | + public boolean equals(Object o) { |
|
| 22 | + if (this == o) return true; |
|
| 23 | + if (o == null || getClass() != o.getClass()) return false; |
|
| 24 | + Product product = (Product) o; |
|
| 25 | + return Objects.equals(name, product.name) && |
|
| 26 | + Objects.equals(price, product.price) && |
|
| 27 | + Objects.equals(sku, product.sku); |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + @Override |
|
| 31 | + public int hashCode() { |
|
| 32 | + return Objects.hash(name, price, sku); |
|
| 33 | + } |
|
| 34 | +} |
Login Required: You must be registered to submit reviews and receive AI feedback.
Register or
login to start reviewing!
Your Review
Review Tips
- Look for security vulnerabilities (SQL injection, XSS, etc.)
- Check for null pointer exceptions and error handling
- Consider performance implications
- Evaluate code maintainability and readability
- Check for proper resource management
- Look for logic errors or edge cases