我在两个表OneToOne之间有关系。我在课堂上建立关系,但是级联持久性不起作用 JPA到达以持续登录,但未填充子类的FK。已经有人在为类似的事情了。
019-04-18 00:37:56.914 DEBUG 16109 --- [nio-8080-exec-1] org.hibernate.SQL :
insert
into
login
(email, perfil_acesso, senha, status)
values
(?, ?, ?, ?)
Hibernate:
insert
into
login
(email, perfil_acesso, senha, status)
values
(?, ?, ?, ?)
2019-04-18 00:37:56.954 TRACE 16109 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [VARCHAR] - [guil5@nilone.com]
2019-04-18 00:37:56.955 TRACE 16109 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [VARCHAR] - [adm]
2019-04-18 00:37:56.955 TRACE 16109 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - [$2a$10$B2rZuTPU.GiWPdt9w29D2u0YXtZCnAu/ZYguGSNife89LyNKxnC5q]
2019-04-18 00:37:56.956 TRACE 16109 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [BOOLEAN] - [true]
2019-04-18 00:37:57.008 DEBUG 16109 --- [nio-8080-exec-1] org.hibernate.SQL :
insert
into
morador
(data_cadastro, data_nascimento, identificacao, login_id, nome, perfil_acesso, sobrenome, telefone)
values
(?, ?, ?, ?, ?, ?, ?, ?)
Hibernate:
insert
into
morador
(data_cadastro, data_nascimento, identificacao, login_id, nome, perfil_acesso, sobrenome, telefone)
values
(?, ?, ?, ?, ?, ?, ?, ?)
2019-04-18 00:37:57.012 TRACE 16109 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [TIMESTAMP] - [Thu Apr 18 00:37:56 BRT 2019]
2019-04-18 00:37:57.016 TRACE 16109 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [2] as [TIMESTAMP] - [Sat Oct 28 22:00:00 BRST 1995]
2019-04-18 00:37:57.017 TRACE 16109 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [3] as [VARCHAR] - [14254364584]
2019-04-18 00:37:57.023 TRACE 16109 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [4] as [INTEGER] - [null]
2019-04-18 00:37:57.024 TRACE 16109 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [5] as [VARCHAR] - [Renanzinho]
2019-04-18 00:37:57.024 TRACE 16109 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [6] as [VARCHAR] - [titular]
2019-04-18 00:37:57.024 TRACE 16109 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [7] as [VARCHAR] - [Dutra]
2019-04-18 00:37:57.024 TRACE 16109 --- [nio-8080-exec-1] o.h.type.descriptor.sql.BasicBinder : binding parameter [8] as [VARCHAR] - [4385-7612]
2019-04-18 00:37:57.057 WARN 16109 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 1048, SQLState: 23000
2019-04-18 00:37:57.057 ERROR 16109 --- [nio-8080-exec-1] o.h.engine.jdbc.spi.SqlExceptionHelper : Column 'login_id' cannot be null
2019-04-18 00:37:57.195 WARN 16109 --- [nio-8080-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; constraint [null]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement]
我的实施情况如何
@Getter
@Setter
@Entity
public class Login {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@OneToOne(mappedBy = "login", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Morador morador;
}
@Getter
@Setter
@Entity
public class Morador{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "login_id")
private Login login;
}