hibernate保存不工作springboot

时间:2018-02-11 07:03:49

标签: hibernate rest spring-boot

我们正在尝试从Hibernate session.save()方法中保存实体,但在日志中它甚至不生成查询而且也不存储在db中。我们正在尝试使用springboot休息。

PatientServiceImpl:

 public Patient createPatient(Patient patient) {
            Session session = SessionUtil.getSession();
        System.out.println("hiii" + patient);
        session.save(patient);
        System.out.println("hiiii");
            return null;
        }

PatientService

@Path("/patientservice")
public interface PatientService { @Path("/patients")
@POST
public Patient createPatient(Patient patient);
}

但我可以通过标准方法获取记录。

以下日志: 2018-02-11 11:58:32.883 INFO 2188 --- [nio-8080-exec-2] .c.i.DriverManagerConnectionProviderImpl:HHH000115:Hibernate连接池大小:20(min = 1) 2018-02-11 11:58:33.201 INFO 2188 --- [nio-8080-exec-2] org.hibernate.dialect.Dialect:HHH000400:使用方言:org.hibernate.dialect.MySQLDialect 2018-02-11 11:58:33.256 INFO 2188 --- [nio-8080-exec-2] o.h.e.j.e.i.LobCreatorBuilderImpl:HHH000423:禁用上下文LOB创建,因为JDBC驱动程序报告JDBC版本[3]小于4 hiiiPatient [pid = 2,pname = bhas,page = 29] hiiii

1 个答案:

答案 0 :(得分:0)

尝试使用flush()实际传输您的对象(患者)

public Patient createPatient(Patient patient) {
    Session session = SessionUtil.getSession();
    System.out.println("hiii" + patient);
    session.save(patient);
    // Right after the save
    session.flush(patient); // This should save the object to database
    System.out.println("hiiii");
    // Not a good idea to return null. Try using Optional in java8
    return null; 
}