首页 > jpa设置ID为默认的@GeneratedValue,不能生成auto_increatement的表

jpa设置ID为默认的@GeneratedValue,不能生成auto_increatement的表

jpa设置ID为默认的@GeneratedValue,不能生存auto_increatement的表,导致如果原表有内容,就出错,说主键重复。这是怎么回事呢?

hibernate 5.1.0

我的实体类:

@Table(name = "sssp_empoyee")
@Entity
public class Employee {

    private Integer id;
    private String lastName;
    private String email;

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date birth;
    private Date crateTime;
    private Department department;

    @GeneratedValue
    @Id
    public Integer getId() {

        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

我的spring设置:


        <property name="jpaProperties">
            <props>
                <prop key="hibernate.implicit_naming_strategy">legacy-jpa</prop>

                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>

                <prop key="hibernate.cache.use_query_cache">true</prop>
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
            </props>
        </property>

        <property name="sharedCacheMode" value="ENABLE_SELECTIVE"/>
【热门文章】
【热门文章】