0
votes

Need help Please in MyBank jEE application. the Problem is that hibernate is able to Create the Tables but it doesn't insert the data here is my code

import java.util.Date;
import org.sid.dao.ClientRepository;
import org.sid.dao.CompteRepository;
import org.sid.entities.Client;
import org.sid.entities.Compte;
import org.sid.entities.CompteCourant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class MyBankApplication implements CommandLineRunner {

    @Autowired
    private ClientRepository clientrepository;

    @Autowired
    private CompteRepository compteRepository;


    public static void main(String[] args) {
        ApplicationContext ctx = SpringApplication.run(MyBankApplication.class, args);
//      ClientRepository clientrepository = ctx.getBean(ClientRepository.class);
//      clientrepository.save(new Client("hassan", "[email protected]"));
    }


    @Override
    public void run(String... arg0) throws Exception {
        Client c1 = clientrepository.save(new Client("Hassan", "[email protected]"));
        Client c2 = clientrepository.save(new Client("Rachide", "[email protected]"));
        Compte cpt = compteRepository.save(new CompteCourant("c1", new Date(), 90000, c1, 5000));
    }

}
package org.sid.dao;

import org.sid.entities.Client;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ClientRepository extends JpaRepository<Client, Long> {

}
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;

@Entity
public class Client implements Serializable {
    @Id
    @GeneratedValue
    private Long code;
    private String nom;
    private String email;
    @OneToMany(mappedBy = "client", fetch = FetchType.LAZY)
    private Collection<Compte> comptes;

    public Client() {
        super();
    }

    public Client(String nom, String email) {
        super();
        this.nom = nom;
        this.email = email;
    }

    public Long getCode() {
        return code;
    }

    public void setCode(Long code) {
        this.code = code;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Collection<Compte> getComptes() {
        return comptes;
    }

    public void setComptes(Collection<Compte> comptes) {
        this.comptes = comptes;
    }


}

Here is the error why it coudn't answer the data to the database

HHH000230: Schema export complete 2017-06-13 17:51:40.270 INFO 73460 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' 2017-06-13 17:51:41.152 INFO 73460 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2eaf2b1: startup date [Tue Jun 13 17:51:30 CEST 2017]; root of context hierarchy 2017-06-13 17:51:41.353 INFO 73460 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 2017-06-13 17:51:41.356 INFO 73460 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) 2017-06-13 17:51:41.440 INFO 73460 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-06-13 17:51:41.441 INFO 73460 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-06-13 17:51:41.577 INFO 73460 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler] 2017-06-13 17:51:42.822 INFO 73460 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729 2017-06-13 17:51:43.115 INFO 73460 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup 2017-06-13 17:51:43.319 INFO 73460 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http) Hibernate: insert into client (email, nom) values (?, ?) Hibernate: insert into client (email, nom) values (?, ?) Hibernate: select comptecour0_.code_compte as code_com2_1_0_, comptecour0_.code_cli as code_cli7_1_0_, comptecour0_.date_creation as date_cre3_1_0_, comptecour0_.solde as solde4_1_0_, comptecour0_.decouvert as decouver6_1_0_ from compte comptecour0_ where comptecour0_.code_compte=? and comptecour0_.type_cpte='CC' Hibernate: select client0_.code as code1_0_0_, client0_.email as email2_0_0_, client0_.nom as nom3_0_0_ from client client0_ where client0_.code=? Hibernate: insert into compte (code_cli, date_creation, solde, decouvert, type_cpte, code_compte) values (?, ?, ?, ?, 'CC', ?) 2017-06-13 17:51:43.633 INFO 73460 --- [ restartedMain] org.sid.MyBankApplication : Started MyBankApplication in 15.741 seconds (JVM running for 16.96) 2017-06-13 17:51:47.555 INFO 73460 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet' 2017-06-13 17:51:47.555 INFO 73460 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started 2017-06-13 17:51:47.585 INFO 73460 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 30 ms

:

1

1 Answers

0
votes

Hibernate: insert into client (email, nom) values (?, ?) Hibernate: insert into client (email, nom) values (?, ?)