Spring getOne(id) issue - existing id's coming up null Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Avoiding != null statementsHow do I check if a file exists in Java?Is null check needed before calling instanceof?Why is my Spring @Autowired field null?How to log SQL statements in Spring Boot?Returning bad credential in oauth2 implemention using spring boot 1.5Spring Webflux Router Functions not being usedSpring boot 2 with OAUTH 2.0 implementation in own authorization serverSpring http API returns error 500 but error is not logged in consolehow to fix 'resource not found' when trying to download file in spring boot REST API?

New Order #6: Easter Egg

Caught masturbating at work

Flight departed from the gate 5 min before scheduled departure time. Refund options

How does TikZ render an arc?

Is there public access to the Meteor Crater in Arizona?

Is it possible for SQL statements to execute concurrently within a single session in SQL Server?

Did any compiler fully use 80-bit floating point?

Is openssl rand command cryptographically secure?

The test team as an enemy of development? And how can this be avoided?

Why datecode is SO IMPORTANT to chip manufacturers?

What does Turing mean by this statement?

Why BitLocker does not use RSA

Does silver oxide react with hydrogen sulfide?

Trying to understand entropy as a novice in thermodynamics

What order were files/directories output in dir?

My mentor says to set image to Fine instead of RAW — how is this different from JPG?

What is the "studentd" process?

Is multiple magic items in one inherently imbalanced?

Why are vacuum tubes still used in amateur radios?

what is the log of the PDF for a Normal Distribution?

Sally's older brother

How much damage would a cupful of neutron star matter do to the Earth?

Delete free apps from Play Store library

How often does castling occur in grandmaster games?



Spring getOne(id) issue - existing id's coming up null



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Avoiding != null statementsHow do I check if a file exists in Java?Is null check needed before calling instanceof?Why is my Spring @Autowired field null?How to log SQL statements in Spring Boot?Returning bad credential in oauth2 implemention using spring boot 1.5Spring Webflux Router Functions not being usedSpring boot 2 with OAUTH 2.0 implementation in own authorization serverSpring http API returns error 500 but error is not logged in consolehow to fix 'resource not found' when trying to download file in spring boot REST API?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am using a newer version of Spring-boot in my project, so instead of using the findById(Long id), I am using getOne(Long id) (the Optional findById wasn't working for me). My "save new form" method works fine, and the SQL database creates an id for the submitted form (aka broker). But when editing the form I can not access the existing id and am getting a null error. Could someone please point me in the right direction here. Is it because I am using getOne method that this is coming back null, or is there something else going on causing this issue?



Here is the trace stack to show the 500 Error for having a null ID.



2019-03-08 14:58:32.416 DEBUG 988 --- [p-nio-64-exec-1] o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for POST "/error", parameters=masked
2019-03-08 14:58:32.417 DEBUG 988 --- [p-nio-64-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-03-08 14:58:32.418 DEBUG 988 --- [p-nio-64-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Using 'application/json', given [*/*] and supported [application/json, application/*+json, application/json, application/*+json]
2019-03-08 14:58:32.418 DEBUG 988 --- [p-nio-64-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Writing [timestamp=Fri Mar 08 14:58:32 PST 2019, status=500, error=Internal Server Error, message=The given id must not be null!; nested exception is java.lang.IllegalArgumentException: The given id must not be null!, path=/saveBroker]
2019-03-08 14:58:32.419 DEBUG 988 --- [p-nio-64-exec-1] o.s.web.servlet.DispatcherServlet : Exiting from "ERROR" dispatch, status 500


Here are my controller functions:



 @RequestMapping(value="/newBroker")
public String newBroker(Model model)
model.addAttribute("broker",new Broker());
return "brokerProfile";


@RequestMapping(value="/addBroker")
public String addBroker(Model model, @ModelAttribute(value="broker") Broker broker)

Long id=null;
try
Broker newBroker = brokerRepository.save(broker);
id = newBroker.getId();
if (broker.getStatus().equals("active"))
broker.setOnboardedDate(LocalDate.now());
brokerRepository.save(newBroker);
catch (DataAccessException e)
e.printStackTrace();


return "redirect:/edit/"+id;


@RequestMapping(value="/edit/id")
public String editbroker(Model model, @PathVariable("id") Long id, Broker broker)
Broker existing= brokerRepository.getOne(id);
model.addAttribute("broker",existing);
return "brokerProfile";



@RequestMapping(value="/saveBroker")
@ResponseBody
public JSONObject saveBroker(Model model, @ModelAttribute(value="broker") Broker broker)

Boolean saved=false;
JSONObject response=new JSONObject();
Broker brokerBeforeUpdate = brokerRepository.getOne(broker.getId());

if (brokerBeforeUpdate!=null && !brokerBeforeUpdate.getStatus().equals("active") && broker.getStatus().equals("active"))
broker.setOnboardedDate(LocalDate.now());
else if (!broker.getStatus().equals("active"))
broker.setOnboardedDate(null);
try
brokerBeforeUpdate=brokerRepository.save(broker);
saved=true;
response.put("brokerId",broker.getId());

catch (DataAccessException e)
e.printStackTrace();
response.put("error",e.getLocalizedMessage());
response.put("cause",e.getLocalizedMessage());

response.put("success",saved);
return response;

}


My Repository pretaining to getOne()/findById



public interface BrokerRepository extends CrudRepository<Broker,Long>, JpaSpecificationExecutor 

Broker save(Broker entity);

// <Optional>Broker findById(Long id);

Broker getOne(Long id);


void delete(Broker entity);

List<Broker> findAll();




Broker. java piece pertaining to ID



@Entity
@Table(name="Broker")
public class Broker
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "brokerId")
private Long id;

public Long getId()
return id;


public void setId(Long id)
this.id = id;












share|improve this question
























  • i don't see this method in CrudRepositorydocs.spring.io/spring-data/commons/docs/current/api/org/…

    – Deadpool
    Mar 9 at 2:22











  • @Deadpool if I use brokerRepository.findById(broker.getId());I get this error: Error:(61, 53) java: reference to findById is ambiguous both method findById(ID) in org.springframework.data.repository.CrudRepository and method <Optional>findById(java.lang.Long) in com.project1.repositories.BrokerRepository match. I found the getOne option in a stackoverflow question.

    – Stacie
    Mar 11 at 16:41











  • @Deadpool, I am not sure how to use Optionals. If I change it to <Optional>B findById(Long id), how am I supposed to call this in my functions? brokerRepository.findById( ---what goes in here??---) ?

    – Stacie
    Mar 13 at 22:34











  • brokerRepository.findById( ---what goes in here??---) id goes there brokerRepository.findById( id)

    – Deadpool
    Mar 13 at 22:40











  • @Deadpool It doesn't work though because I get Error: java: reference to findById is ambiguous both method findById(ID) org.springframework.data.repository.CrudRepository and method <Optional>findById(java.lang.Long) in com.Portal.repositories.BrokerRepository match

    – Stacie
    Mar 13 at 23:02


















0















I am using a newer version of Spring-boot in my project, so instead of using the findById(Long id), I am using getOne(Long id) (the Optional findById wasn't working for me). My "save new form" method works fine, and the SQL database creates an id for the submitted form (aka broker). But when editing the form I can not access the existing id and am getting a null error. Could someone please point me in the right direction here. Is it because I am using getOne method that this is coming back null, or is there something else going on causing this issue?



Here is the trace stack to show the 500 Error for having a null ID.



2019-03-08 14:58:32.416 DEBUG 988 --- [p-nio-64-exec-1] o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for POST "/error", parameters=masked
2019-03-08 14:58:32.417 DEBUG 988 --- [p-nio-64-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-03-08 14:58:32.418 DEBUG 988 --- [p-nio-64-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Using 'application/json', given [*/*] and supported [application/json, application/*+json, application/json, application/*+json]
2019-03-08 14:58:32.418 DEBUG 988 --- [p-nio-64-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Writing [timestamp=Fri Mar 08 14:58:32 PST 2019, status=500, error=Internal Server Error, message=The given id must not be null!; nested exception is java.lang.IllegalArgumentException: The given id must not be null!, path=/saveBroker]
2019-03-08 14:58:32.419 DEBUG 988 --- [p-nio-64-exec-1] o.s.web.servlet.DispatcherServlet : Exiting from "ERROR" dispatch, status 500


Here are my controller functions:



 @RequestMapping(value="/newBroker")
public String newBroker(Model model)
model.addAttribute("broker",new Broker());
return "brokerProfile";


@RequestMapping(value="/addBroker")
public String addBroker(Model model, @ModelAttribute(value="broker") Broker broker)

Long id=null;
try
Broker newBroker = brokerRepository.save(broker);
id = newBroker.getId();
if (broker.getStatus().equals("active"))
broker.setOnboardedDate(LocalDate.now());
brokerRepository.save(newBroker);
catch (DataAccessException e)
e.printStackTrace();


return "redirect:/edit/"+id;


@RequestMapping(value="/edit/id")
public String editbroker(Model model, @PathVariable("id") Long id, Broker broker)
Broker existing= brokerRepository.getOne(id);
model.addAttribute("broker",existing);
return "brokerProfile";



@RequestMapping(value="/saveBroker")
@ResponseBody
public JSONObject saveBroker(Model model, @ModelAttribute(value="broker") Broker broker)

Boolean saved=false;
JSONObject response=new JSONObject();
Broker brokerBeforeUpdate = brokerRepository.getOne(broker.getId());

if (brokerBeforeUpdate!=null && !brokerBeforeUpdate.getStatus().equals("active") && broker.getStatus().equals("active"))
broker.setOnboardedDate(LocalDate.now());
else if (!broker.getStatus().equals("active"))
broker.setOnboardedDate(null);
try
brokerBeforeUpdate=brokerRepository.save(broker);
saved=true;
response.put("brokerId",broker.getId());

catch (DataAccessException e)
e.printStackTrace();
response.put("error",e.getLocalizedMessage());
response.put("cause",e.getLocalizedMessage());

response.put("success",saved);
return response;

}


My Repository pretaining to getOne()/findById



public interface BrokerRepository extends CrudRepository<Broker,Long>, JpaSpecificationExecutor 

Broker save(Broker entity);

// <Optional>Broker findById(Long id);

Broker getOne(Long id);


void delete(Broker entity);

List<Broker> findAll();




Broker. java piece pertaining to ID



@Entity
@Table(name="Broker")
public class Broker
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "brokerId")
private Long id;

public Long getId()
return id;


public void setId(Long id)
this.id = id;












share|improve this question
























  • i don't see this method in CrudRepositorydocs.spring.io/spring-data/commons/docs/current/api/org/…

    – Deadpool
    Mar 9 at 2:22











  • @Deadpool if I use brokerRepository.findById(broker.getId());I get this error: Error:(61, 53) java: reference to findById is ambiguous both method findById(ID) in org.springframework.data.repository.CrudRepository and method <Optional>findById(java.lang.Long) in com.project1.repositories.BrokerRepository match. I found the getOne option in a stackoverflow question.

    – Stacie
    Mar 11 at 16:41











  • @Deadpool, I am not sure how to use Optionals. If I change it to <Optional>B findById(Long id), how am I supposed to call this in my functions? brokerRepository.findById( ---what goes in here??---) ?

    – Stacie
    Mar 13 at 22:34











  • brokerRepository.findById( ---what goes in here??---) id goes there brokerRepository.findById( id)

    – Deadpool
    Mar 13 at 22:40











  • @Deadpool It doesn't work though because I get Error: java: reference to findById is ambiguous both method findById(ID) org.springframework.data.repository.CrudRepository and method <Optional>findById(java.lang.Long) in com.Portal.repositories.BrokerRepository match

    – Stacie
    Mar 13 at 23:02














0












0








0


1






I am using a newer version of Spring-boot in my project, so instead of using the findById(Long id), I am using getOne(Long id) (the Optional findById wasn't working for me). My "save new form" method works fine, and the SQL database creates an id for the submitted form (aka broker). But when editing the form I can not access the existing id and am getting a null error. Could someone please point me in the right direction here. Is it because I am using getOne method that this is coming back null, or is there something else going on causing this issue?



Here is the trace stack to show the 500 Error for having a null ID.



2019-03-08 14:58:32.416 DEBUG 988 --- [p-nio-64-exec-1] o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for POST "/error", parameters=masked
2019-03-08 14:58:32.417 DEBUG 988 --- [p-nio-64-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-03-08 14:58:32.418 DEBUG 988 --- [p-nio-64-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Using 'application/json', given [*/*] and supported [application/json, application/*+json, application/json, application/*+json]
2019-03-08 14:58:32.418 DEBUG 988 --- [p-nio-64-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Writing [timestamp=Fri Mar 08 14:58:32 PST 2019, status=500, error=Internal Server Error, message=The given id must not be null!; nested exception is java.lang.IllegalArgumentException: The given id must not be null!, path=/saveBroker]
2019-03-08 14:58:32.419 DEBUG 988 --- [p-nio-64-exec-1] o.s.web.servlet.DispatcherServlet : Exiting from "ERROR" dispatch, status 500


Here are my controller functions:



 @RequestMapping(value="/newBroker")
public String newBroker(Model model)
model.addAttribute("broker",new Broker());
return "brokerProfile";


@RequestMapping(value="/addBroker")
public String addBroker(Model model, @ModelAttribute(value="broker") Broker broker)

Long id=null;
try
Broker newBroker = brokerRepository.save(broker);
id = newBroker.getId();
if (broker.getStatus().equals("active"))
broker.setOnboardedDate(LocalDate.now());
brokerRepository.save(newBroker);
catch (DataAccessException e)
e.printStackTrace();


return "redirect:/edit/"+id;


@RequestMapping(value="/edit/id")
public String editbroker(Model model, @PathVariable("id") Long id, Broker broker)
Broker existing= brokerRepository.getOne(id);
model.addAttribute("broker",existing);
return "brokerProfile";



@RequestMapping(value="/saveBroker")
@ResponseBody
public JSONObject saveBroker(Model model, @ModelAttribute(value="broker") Broker broker)

Boolean saved=false;
JSONObject response=new JSONObject();
Broker brokerBeforeUpdate = brokerRepository.getOne(broker.getId());

if (brokerBeforeUpdate!=null && !brokerBeforeUpdate.getStatus().equals("active") && broker.getStatus().equals("active"))
broker.setOnboardedDate(LocalDate.now());
else if (!broker.getStatus().equals("active"))
broker.setOnboardedDate(null);
try
brokerBeforeUpdate=brokerRepository.save(broker);
saved=true;
response.put("brokerId",broker.getId());

catch (DataAccessException e)
e.printStackTrace();
response.put("error",e.getLocalizedMessage());
response.put("cause",e.getLocalizedMessage());

response.put("success",saved);
return response;

}


My Repository pretaining to getOne()/findById



public interface BrokerRepository extends CrudRepository<Broker,Long>, JpaSpecificationExecutor 

Broker save(Broker entity);

// <Optional>Broker findById(Long id);

Broker getOne(Long id);


void delete(Broker entity);

List<Broker> findAll();




Broker. java piece pertaining to ID



@Entity
@Table(name="Broker")
public class Broker
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "brokerId")
private Long id;

public Long getId()
return id;


public void setId(Long id)
this.id = id;












share|improve this question
















I am using a newer version of Spring-boot in my project, so instead of using the findById(Long id), I am using getOne(Long id) (the Optional findById wasn't working for me). My "save new form" method works fine, and the SQL database creates an id for the submitted form (aka broker). But when editing the form I can not access the existing id and am getting a null error. Could someone please point me in the right direction here. Is it because I am using getOne method that this is coming back null, or is there something else going on causing this issue?



Here is the trace stack to show the 500 Error for having a null ID.



2019-03-08 14:58:32.416 DEBUG 988 --- [p-nio-64-exec-1] o.s.web.servlet.DispatcherServlet : "ERROR" dispatch for POST "/error", parameters=masked
2019-03-08 14:58:32.417 DEBUG 988 --- [p-nio-64-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2019-03-08 14:58:32.418 DEBUG 988 --- [p-nio-64-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Using 'application/json', given [*/*] and supported [application/json, application/*+json, application/json, application/*+json]
2019-03-08 14:58:32.418 DEBUG 988 --- [p-nio-64-exec-1] o.s.w.s.m.m.a.HttpEntityMethodProcessor : Writing [timestamp=Fri Mar 08 14:58:32 PST 2019, status=500, error=Internal Server Error, message=The given id must not be null!; nested exception is java.lang.IllegalArgumentException: The given id must not be null!, path=/saveBroker]
2019-03-08 14:58:32.419 DEBUG 988 --- [p-nio-64-exec-1] o.s.web.servlet.DispatcherServlet : Exiting from "ERROR" dispatch, status 500


Here are my controller functions:



 @RequestMapping(value="/newBroker")
public String newBroker(Model model)
model.addAttribute("broker",new Broker());
return "brokerProfile";


@RequestMapping(value="/addBroker")
public String addBroker(Model model, @ModelAttribute(value="broker") Broker broker)

Long id=null;
try
Broker newBroker = brokerRepository.save(broker);
id = newBroker.getId();
if (broker.getStatus().equals("active"))
broker.setOnboardedDate(LocalDate.now());
brokerRepository.save(newBroker);
catch (DataAccessException e)
e.printStackTrace();


return "redirect:/edit/"+id;


@RequestMapping(value="/edit/id")
public String editbroker(Model model, @PathVariable("id") Long id, Broker broker)
Broker existing= brokerRepository.getOne(id);
model.addAttribute("broker",existing);
return "brokerProfile";



@RequestMapping(value="/saveBroker")
@ResponseBody
public JSONObject saveBroker(Model model, @ModelAttribute(value="broker") Broker broker)

Boolean saved=false;
JSONObject response=new JSONObject();
Broker brokerBeforeUpdate = brokerRepository.getOne(broker.getId());

if (brokerBeforeUpdate!=null && !brokerBeforeUpdate.getStatus().equals("active") && broker.getStatus().equals("active"))
broker.setOnboardedDate(LocalDate.now());
else if (!broker.getStatus().equals("active"))
broker.setOnboardedDate(null);
try
brokerBeforeUpdate=brokerRepository.save(broker);
saved=true;
response.put("brokerId",broker.getId());

catch (DataAccessException e)
e.printStackTrace();
response.put("error",e.getLocalizedMessage());
response.put("cause",e.getLocalizedMessage());

response.put("success",saved);
return response;

}


My Repository pretaining to getOne()/findById



public interface BrokerRepository extends CrudRepository<Broker,Long>, JpaSpecificationExecutor 

Broker save(Broker entity);

// <Optional>Broker findById(Long id);

Broker getOne(Long id);


void delete(Broker entity);

List<Broker> findAll();




Broker. java piece pertaining to ID



@Entity
@Table(name="Broker")
public class Broker
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "brokerId")
private Long id;

public Long getId()
return id;


public void setId(Long id)
this.id = id;









java spring hibernate spring-boot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 2:17









Deadpool

8,2372831




8,2372831










asked Mar 8 at 23:32









StacieStacie

1139




1139












  • i don't see this method in CrudRepositorydocs.spring.io/spring-data/commons/docs/current/api/org/…

    – Deadpool
    Mar 9 at 2:22











  • @Deadpool if I use brokerRepository.findById(broker.getId());I get this error: Error:(61, 53) java: reference to findById is ambiguous both method findById(ID) in org.springframework.data.repository.CrudRepository and method <Optional>findById(java.lang.Long) in com.project1.repositories.BrokerRepository match. I found the getOne option in a stackoverflow question.

    – Stacie
    Mar 11 at 16:41











  • @Deadpool, I am not sure how to use Optionals. If I change it to <Optional>B findById(Long id), how am I supposed to call this in my functions? brokerRepository.findById( ---what goes in here??---) ?

    – Stacie
    Mar 13 at 22:34











  • brokerRepository.findById( ---what goes in here??---) id goes there brokerRepository.findById( id)

    – Deadpool
    Mar 13 at 22:40











  • @Deadpool It doesn't work though because I get Error: java: reference to findById is ambiguous both method findById(ID) org.springframework.data.repository.CrudRepository and method <Optional>findById(java.lang.Long) in com.Portal.repositories.BrokerRepository match

    – Stacie
    Mar 13 at 23:02


















  • i don't see this method in CrudRepositorydocs.spring.io/spring-data/commons/docs/current/api/org/…

    – Deadpool
    Mar 9 at 2:22











  • @Deadpool if I use brokerRepository.findById(broker.getId());I get this error: Error:(61, 53) java: reference to findById is ambiguous both method findById(ID) in org.springframework.data.repository.CrudRepository and method <Optional>findById(java.lang.Long) in com.project1.repositories.BrokerRepository match. I found the getOne option in a stackoverflow question.

    – Stacie
    Mar 11 at 16:41











  • @Deadpool, I am not sure how to use Optionals. If I change it to <Optional>B findById(Long id), how am I supposed to call this in my functions? brokerRepository.findById( ---what goes in here??---) ?

    – Stacie
    Mar 13 at 22:34











  • brokerRepository.findById( ---what goes in here??---) id goes there brokerRepository.findById( id)

    – Deadpool
    Mar 13 at 22:40











  • @Deadpool It doesn't work though because I get Error: java: reference to findById is ambiguous both method findById(ID) org.springframework.data.repository.CrudRepository and method <Optional>findById(java.lang.Long) in com.Portal.repositories.BrokerRepository match

    – Stacie
    Mar 13 at 23:02

















i don't see this method in CrudRepositorydocs.spring.io/spring-data/commons/docs/current/api/org/…

– Deadpool
Mar 9 at 2:22





i don't see this method in CrudRepositorydocs.spring.io/spring-data/commons/docs/current/api/org/…

– Deadpool
Mar 9 at 2:22













@Deadpool if I use brokerRepository.findById(broker.getId());I get this error: Error:(61, 53) java: reference to findById is ambiguous both method findById(ID) in org.springframework.data.repository.CrudRepository and method <Optional>findById(java.lang.Long) in com.project1.repositories.BrokerRepository match. I found the getOne option in a stackoverflow question.

– Stacie
Mar 11 at 16:41





@Deadpool if I use brokerRepository.findById(broker.getId());I get this error: Error:(61, 53) java: reference to findById is ambiguous both method findById(ID) in org.springframework.data.repository.CrudRepository and method <Optional>findById(java.lang.Long) in com.project1.repositories.BrokerRepository match. I found the getOne option in a stackoverflow question.

– Stacie
Mar 11 at 16:41













@Deadpool, I am not sure how to use Optionals. If I change it to <Optional>B findById(Long id), how am I supposed to call this in my functions? brokerRepository.findById( ---what goes in here??---) ?

– Stacie
Mar 13 at 22:34





@Deadpool, I am not sure how to use Optionals. If I change it to <Optional>B findById(Long id), how am I supposed to call this in my functions? brokerRepository.findById( ---what goes in here??---) ?

– Stacie
Mar 13 at 22:34













brokerRepository.findById( ---what goes in here??---) id goes there brokerRepository.findById( id)

– Deadpool
Mar 13 at 22:40





brokerRepository.findById( ---what goes in here??---) id goes there brokerRepository.findById( id)

– Deadpool
Mar 13 at 22:40













@Deadpool It doesn't work though because I get Error: java: reference to findById is ambiguous both method findById(ID) org.springframework.data.repository.CrudRepository and method <Optional>findById(java.lang.Long) in com.Portal.repositories.BrokerRepository match

– Stacie
Mar 13 at 23:02






@Deadpool It doesn't work though because I get Error: java: reference to findById is ambiguous both method findById(ID) org.springframework.data.repository.CrudRepository and method <Optional>findById(java.lang.Long) in com.Portal.repositories.BrokerRepository match

– Stacie
Mar 13 at 23:02













1 Answer
1






active

oldest

votes


















0














I think you need to specify the method used in the @RequestMethod because it has no default value



@RequestMapping(path="/",method=RequestMethod.GET or POST)


but you use this instead of @RequestMethod



@PostMethod(path='/')
@GetMethod(path='/')






share|improve this answer

























  • GET is default for @RequestMapping

    – Strelok
    Mar 9 at 12:53











  • I'm not sure that the @requestMapping is the issue since it does post new brokers. If I specify the Post of Get method, I will have to repeat the code in the method so it works for both otherwise I get a 405 error. Is there not a way to get the method to work when finding the id?

    – Stacie
    Mar 11 at 16:50











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072424%2fspring-getoneid-issue-existing-ids-coming-up-null%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I think you need to specify the method used in the @RequestMethod because it has no default value



@RequestMapping(path="/",method=RequestMethod.GET or POST)


but you use this instead of @RequestMethod



@PostMethod(path='/')
@GetMethod(path='/')






share|improve this answer

























  • GET is default for @RequestMapping

    – Strelok
    Mar 9 at 12:53











  • I'm not sure that the @requestMapping is the issue since it does post new brokers. If I specify the Post of Get method, I will have to repeat the code in the method so it works for both otherwise I get a 405 error. Is there not a way to get the method to work when finding the id?

    – Stacie
    Mar 11 at 16:50















0














I think you need to specify the method used in the @RequestMethod because it has no default value



@RequestMapping(path="/",method=RequestMethod.GET or POST)


but you use this instead of @RequestMethod



@PostMethod(path='/')
@GetMethod(path='/')






share|improve this answer

























  • GET is default for @RequestMapping

    – Strelok
    Mar 9 at 12:53











  • I'm not sure that the @requestMapping is the issue since it does post new brokers. If I specify the Post of Get method, I will have to repeat the code in the method so it works for both otherwise I get a 405 error. Is there not a way to get the method to work when finding the id?

    – Stacie
    Mar 11 at 16:50













0












0








0







I think you need to specify the method used in the @RequestMethod because it has no default value



@RequestMapping(path="/",method=RequestMethod.GET or POST)


but you use this instead of @RequestMethod



@PostMethod(path='/')
@GetMethod(path='/')






share|improve this answer















I think you need to specify the method used in the @RequestMethod because it has no default value



@RequestMapping(path="/",method=RequestMethod.GET or POST)


but you use this instead of @RequestMethod



@PostMethod(path='/')
@GetMethod(path='/')







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 9 at 1:38

























answered Mar 9 at 0:38









Chady M'barkiChady M'barki

362




362












  • GET is default for @RequestMapping

    – Strelok
    Mar 9 at 12:53











  • I'm not sure that the @requestMapping is the issue since it does post new brokers. If I specify the Post of Get method, I will have to repeat the code in the method so it works for both otherwise I get a 405 error. Is there not a way to get the method to work when finding the id?

    – Stacie
    Mar 11 at 16:50

















  • GET is default for @RequestMapping

    – Strelok
    Mar 9 at 12:53











  • I'm not sure that the @requestMapping is the issue since it does post new brokers. If I specify the Post of Get method, I will have to repeat the code in the method so it works for both otherwise I get a 405 error. Is there not a way to get the method to work when finding the id?

    – Stacie
    Mar 11 at 16:50
















GET is default for @RequestMapping

– Strelok
Mar 9 at 12:53





GET is default for @RequestMapping

– Strelok
Mar 9 at 12:53













I'm not sure that the @requestMapping is the issue since it does post new brokers. If I specify the Post of Get method, I will have to repeat the code in the method so it works for both otherwise I get a 405 error. Is there not a way to get the method to work when finding the id?

– Stacie
Mar 11 at 16:50





I'm not sure that the @requestMapping is the issue since it does post new brokers. If I specify the Post of Get method, I will have to repeat the code in the method so it works for both otherwise I get a 405 error. Is there not a way to get the method to work when finding the id?

– Stacie
Mar 11 at 16:50



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072424%2fspring-getoneid-issue-existing-ids-coming-up-null%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко