Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Part 5: Touring your secured REST service #111

Open
DominikZig opened this issue Oct 28, 2019 · 2 comments
Open

Part 5: Touring your secured REST service #111

DominikZig opened this issue Oct 28, 2019 · 2 comments

Comments

@DominikZig
Copy link

Hi,

I just finished Part 5 of the tutorial, but I had trouble curling the first employee id as shown in the example under Touring you secured REST service. In the example, it says to "curl -v -u greg:turnquist localhost:8080/api/employees/1", which returns Frodo Baggins (as he's the first employee in the database). However, for me, when I try and curl the employee id 1, it gives me a 404 instead of returning the Frodo Baggins employee (the same happens for employee id 2 as well). I can successfully retrieve Frodo Baggins when I curl id 3 though, which returns the employee details as normal.

Essentially, my employees id's seem to be starting at 3 and not 1. My theory is maybe this is due to the two managers being created who also have id's and they're being created first?

@maldonadojsm
Copy link

Yeah, I'm having the same issues. My employee count is starting at 3 rather than at 1

@yukihane
Copy link

When change @GeneratedValue strategy AUTO to IDENTITY, it will work expected.

diff --git a/security/src/main/java/com/greglturnquist/payroll/Employee.java b/security/src/main/java/com/greglturnquist/payroll/Employee.java
index 9f7950d..90690ca 100644
--- a/security/src/main/java/com/greglturnquist/payroll/Employee.java
+++ b/security/src/main/java/com/greglturnquist/payroll/Employee.java
@@ -19,6 +19,7 @@ import java.util.Objects;
 
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.ManyToOne;
 import javax.persistence.Version;
@@ -32,7 +33,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
 @Entity
 public class Employee {
 
-	private @Id @GeneratedValue Long id;
+	private @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Long id;
 	private String firstName;
 	private String lastName;
 	private String description;
diff --git a/security/src/main/java/com/greglturnquist/payroll/Manager.java b/security/src/main/java/com/greglturnquist/payroll/Manager.java
index 2445690..fcba774 100644
--- a/security/src/main/java/com/greglturnquist/payroll/Manager.java
+++ b/security/src/main/java/com/greglturnquist/payroll/Manager.java
@@ -20,6 +20,7 @@ import java.util.Objects;
 
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
 import javax.persistence.Id;
 
 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@@ -36,7 +37,7 @@ public class Manager {
 
 	public static final PasswordEncoder PASSWORD_ENCODER = new BCryptPasswordEncoder(); // <1>
 
-	private @Id @GeneratedValue Long id; // <2>
+	private @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Long id; // <2>
 
 	private String name; // <2>

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants