需要帮助请在MyBank jEE应用程序中。问题是hibernate能够创建表但是它不会在这里插入数据是我的代码
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", "hassan@gmail.com"));
}
@Override
public void run(String... arg0) throws Exception {
Client c1 = clientrepository.save(new Client("Hassan", "hasan@gmail.com"));
Client c2 = clientrepository.save(new Client("Rachide", "Rachide@gmail.com"));
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;
}
}
这是为什么它不能将数据应答到数据库
的错误HHH000230:架构导出完成 2017-06-13 17:51:40.270 INFO 73460 --- [restartedMain] j.LocalContainerEntityManagerFactoryBean:初始化的JPA EntityManagerFactory用于持久性单元'default' 2017-06-13 17:51:41.152 INFO 73460 --- [restartedMain] swsmmaRequestMappingHandlerAdapter:寻找@ControllerAdvice:org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@2eaf2b1:启动日期[Tue Jun 13 17:51: 30 CEST 2017];上下文层次结构的根 2017-06-13 17:51:41.353 INFO 73460 --- [restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping:将“{[/ error]}”映射到公共org.springframework.http.ResponseEntity&gt; org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest) 2017-06-13 17:51:41.356 INFO 73460 --- [restartedMain] swsmmaRequestMappingHandlerMapping:将“{[/ error],produce = [text / html]}”映射到公共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] oswshandler.SimpleUrlHandlerMapping:将URL路径[/ webjars / ]映射到[class org.springframework.web.servlet.resource]类型的处理程序。 ResourceHttpRequestHandler] 2017-06-13 17:51:41.441 INFO 73460 --- [restartedMain] oswshandler.SimpleUrlHandlerMapping:映射的URL路径[/ ]到类型为[class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]的处理程序] 2017-06-13 17:51:41.577 INFO 73460 --- [restartedMain] oswshandler.SimpleUrlHandlerMapping:将URL路径[/**/favicon.ico]映射到[class org.springframework.web.servlet.resource]类型的处理程序.ResourceHttpRequestHandler] 2017-06-13 17:51:42.822 INFO 73460 --- [restartedMain] o.s.b.d.a.OptionalLiveReloadServer:LiveReload服务器在端口35729上运行 2017-06-13 17:51:43.115 INFO 73460 --- [restartedMain] o.s.j.e.a.AnnotationMBeanExporter:在启动时为JMX曝光注册bean 2017-06-13 17:51:43.319 INFO 73460 --- [restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer:Tomcat在端口上启动:8080(http) Hibernate:插入客户端(email,nom)值(?,?) Hibernate:插入客户端(email,nom)值(?,?) Hibernate:选择comptecour0_.code_compte作为code_com2_1_0_,comptecour0_.code_cli作为code_cli7_1_0_,comptecour0_.date_creation作为date_cre3_1_0_,comptecour0_.solde作为solde4_1_0_,comptecour0_.decouvert作为decouver6_1_0_来自compte comptecour0_其中comptecour0_.code_compte =?和comptecour0_.type_cpte ='CC' Hibernate:选择client0_.code作为code1_0_0_,client0_.email作为email2_0_0_,client0_.nom作为nom3_0_0_来自客户端client0_,其中client0_.code =? Hibernate:插入compte(code_cli,date_creation,solde,decouvert,type_cpte,code_compte)值(?,?,?,?,'CC',?) 2017-06-13 17:51:43.633 INFO 73460 --- [restartedMain] org.sid.MyBankApplication:在15.741秒内启动MyBankApplication(JVM运行16.96) 2017-06-13 17:51:47.555 INFO 73460 --- [nio-8080-exec-1] o.a.c.c.C. [Tomcat]。[localhost]。[/]:初始化Spring FrameworkServlet'dispatcherServlet' 2017-06-13 17:51:47.555 INFO 73460 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet:FrameworkServlet'dispatcherServlet':初始化已启动 2017-06-13 17:51:47.585 INFO 73460 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet:FrameworkServlet'dispatcherServlet':初始化在30毫秒内完成
答案 0 :(得分:0)
Hibernate:插入客户端(email,nom)值(?,?) Hibernate:插入客户端(email,nom)值(?,?)