多个Spring boot 2.0.1 整合 JPA 自增失效,

2019-06-28  本文已影响0人  大继

问题描述

整合 network、user、wechat、cent等模块后,用户ID 自增失效。

关键代码及问题重现过程

@Entity
@Table(name = "user")
public class User implements Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;

    @Column(length = 765)
    private String image;

    @Column
    private String name;

    @Column
    private String signature;

    @Column(length = 3)
    private String sex;

    @Column
    private Date updateTime;

    @Column
    private Date createTime;
}

单独模块时可以正常运行!

User user = new User();
user.setCreateTime(new Date());
user.setName(usernameRegisterRequest.getUsername());
user.setUpdateTime(new Date());

userRepository.save(user);
//保存成功

整合模块后出现问题如果下: Field 'id' doesn't have a default value

Hibernate: insert into user (create_time, image, name, sex, signature, update_time) values (?, ?, ?, ?, ?, ?)
2018-04-26 14:56:37.457  WARN 30572 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 1364, SQLState: HY000
2018-04-26 14:56:37.457 ERROR 30572 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : Field 'id' doesn't have a default value

开始排查

<dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>2.4.2</version>
        </dependency>

        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-dysmsapi</artifactId>
            <version>1.0.0</version>
        </dependency>
@Entity
@Table(name = "user")
public class User implements Serializable
@Entity
@Table(name = "user")
public class Sms implements Serializable 

发现问题

解决方法

上一篇下一篇

猜你喜欢

热点阅读