hibernate 为什么我在Springboot应用程序中得到这个异常?[已关闭]

bihw5rsg  于 2023-08-06  发布在  Spring
关注(0)|答案(1)|浏览(106)

**已关闭。**此问题需要debugging details。它目前不接受回答。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答这个问题。
13天前关闭
Improve this question
如何解决这个问题
如何解决此问题?我到底犯了什么错误,我不能确定?
第一个月

@RestController
public class CustomerAccountsControllerImpl  {

    @Autowired 
    private AccountsService accountService;
    
    
    @RequestMapping(value="/createAccount",method = RequestMethod.POST)
    public Accounts createAccount(@RequestBody Accounts value,@RequestHeader(name = "User-Id",required = true) 
    @Pattern(regexp = "^[0-9a-z]{12}", message = "Please enter valid UserId")
    @Valid @Parameter(name ="User-Id",description = "user id") Integer userId) throws AccountCreationException {
         
        
    Accounts AccountCreated = accountService.createAccount(value, userId);
    System.out.println("Dear" + userId + "your Account has been created");
    if(AccountCreated!=null)
    {
        int user = value.getUserId();
        System.out.println("Dear" + user + "your Account has been created");
    }
    else
    {
        throw new AccountCreationException("There is an Issue while Creating "
                + "your account please try after sometime");
    }
        
        return AccountCreated;
    }

}

字符串
Service Implementation

package com.icicibank.accounts.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.icicibank.accounts.model.Accounts;
import com.icicibank.accounts.repository.AccountsRespository;

@Service
public class AccountsServiceImpl implements AccountsService {

    @Autowired
    private AccountsRespository accountrepo;

    private static final Logger LOG = LoggerFactory.getLogger(AccountsServiceImpl.class);

    Accounts created = null;
    @Override
    public Accounts createAccount(Accounts data, Integer userId) {
        try {
            
            if (data != null && !userId.equals(null))
            {
                data.setUserId(userId);
                created = accountrepo.save(data);
            } 
            else 
            {
                LOG.debug("Data input is empty or userId is null please check the iputs once again");
            }
            
        } 
        catch (Exception e) {
            LOG.debug("Hey there is an Exception while calling the craeteAccount " + 
        "method in AccountsServiceImpl");
        }
        return created;

    }

}


Repository Interface

@Repository
public interface AccountsRespository extends CrudRepository<Accounts,String> 
{
    //@SuppressWarnings("unchecked")
    //public Accounts save(Accounts craeteAccount);
    
}


Model Class

@Entity
@Data
public class Accounts {
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private String accountNumber;
    
    @Column
    private int transactionNumber;
    
    @Column
    private int userId;
    
    @Column
    private int upiIdLimit;
    
    @Column
    private double accountBalance;
    
    @Column
    private String transactionLimitPerDay;
}


application.properties file

server.port = 8083
spring.mvc.pathmatch.matching-strategy=ant-path-matcher
spring.datasource.username=user
spring.datasource.password=usernames
spring.datasource.url=jdbc:mysql://localhost:3306/ICICIBANKBHIMUPIDB
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.application.name=Accounts


Log File

[2m2023-07-23 15:35:53.024[0;39m [32m INFO[0;39m [35m11284[0;39m [2m---[0;39m [2m[nio-8083-exec-2][0;39m [36mo.s.web.servlet.DispatcherServlet       [0;39m [2m:[0;39m Initializing Servlet 'dispatcherServlet'
[2m2023-07-23 15:35:53.026[0;39m [32m INFO[0;39m [35m11284[0;39m [2m---[0;39m [2m[nio-8083-exec-2][0;39m [36mo.s.web.servlet.DispatcherServlet       [0;39m [2m:[0;39m Completed initialization in 2 ms
Dear543214466your Account has been created
[2m2023-07-23 15:35:53.155[0;39m [31mERROR[0;39m [35m11284[0;39m [2m---[0;39m [2m[nio-8083-exec-2][0;39m [36mo.a.c.c.C.[.[.[/].[dispatcherServlet]   [0;39m [2m:[0;39m Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.icicibank.accounts.Exceptions.AccountCreationException: There is an Issue while Creating your account please try after sometime] with root cause
Here is the Log File

的字符串
Root Cause in Log File

com.icicibank.accounts.Exceptions.AccountCreationException: There is an Issue while Creating your account please try after sometime
    at com.icicibank.accounts.controller.CustomerAccountsControllerImpl.createAccount(CustomerAccountsControllerImpl.java:38) ~[classes/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.29.jar:5.3.29]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.29.jar:5.3.29]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.29.jar:5.3.29]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.29.jar:5.3.29]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.29.jar:5.3.29]
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.29.jar:5.3.29]
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1072) ~[spring-webmvc-5.3.29.jar:5.3.29]
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:965) ~[spring-webmvc-5.3.29.jar:5.3.29]
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.29.jar:5.3.29]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.29.jar:5.3.29]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:555) ~[tomcat-embed-core-9.0.78.jar:4.0.FR]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.29.jar:5.3.29]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:623) ~[tomcat-embed-core-9.0.78.jar:4.0.FR]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:209) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) ~[tomcat-embed-websocket-9.0.78.jar:9.0.78]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.29.jar:5.3.29]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.29.jar:5.3.29]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.29.jar:5.3.29]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.29.jar:5.3.29]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.29.jar:5.3.29]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.29.jar:5.3.29]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:481) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:130) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:390) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:926) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1791) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.78.jar:9.0.78]
    at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]


..................................................................................................................................................................................................................

hc8w905p

hc8w905p1#

您的数据似乎未保存到数据存储。可能原因:生成的主键不正确。
您的帐户实体的ID类型=String

请尝试对主键使用以下注解:

1.通用生成器注解
1.@GeneratedValue(generator =“uuid”)
范例:

@Id
@GeneratedValue(generator = "uuid")
@GenericGenerator(name = "uuid", strategy = "uuid2")
private String accountNumber;

字符串

第二个选项:

主键可以使用Integer/Long/UUID类型:实体字段:

@Id
@GeneratedValue
private Long accountNumber;


Repository(CrudRepository<Accounts,Long>);

@Repository
public interface AccountsRespository extends CrudRepository<Accounts, Long> 
{

}

相关问题