Spring getOne(id) issue - existing id's coming up nullAvoiding != 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?

Could gravitational lensing be used to protect a spaceship from a laser?

Do I have a twin with permutated remainders?

Infinite Abelian subgroup of infinite non Abelian group example

Why is the 'in' operator throwing an error with a string literal instead of logging false?

How to model explosives?

UK: Is there precedent for the governments e-petition site changing the direction of a government decision?

Assassin's bullet with mercury

Forgetting the musical notes while performing in concert

How to prevent "they're falling in love" trope

Why are electrically insulating heatsinks so rare? Is it just cost?

Can a virus destroy the BIOS of a modern computer?

Is "remove commented out code" correct English?

Is delete *p an alternative to delete [] p?

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

Arrow those variables!

Stopping power of mountain vs road bike

90's TV series where a boy goes to another dimension through portal near power lines

Alternative to sending password over mail?

How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?

What to put in ESTA if staying in US for a few days before going on to Canada

What is the PIE reconstruction for word-initial alpha with rough breathing?

Neighboring nodes in the network

prove that the matrix A is diagonalizable

I Accidentally Deleted a Stock Terminal Theme



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


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

7,8222831




7,8222831










asked Mar 8 at 23:32









StacieStacie

1069




1069












  • 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

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page