Как сделать каскадное сохранение с помощью JPA - PullRequest
0 голосов
/ 18 апреля 2019

У меня есть связь между двумя таблицами, которые являются 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;

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...