JPA通用策略生成器
查看JPA的源码可知:
packagejavax.persistence; /** * Defines the types of primary key generation strategies. ** @see GeneratedValue** @since Java Persistence 1.0*/publicenumGenerationType { /*** Indicates that the persistence provider must assign * primary keys for the entity using an underlying * database table to ensure uniqueness.*/TABLE, /*** Indicates that the persistence provider must assign * primary keys for the entity using a database sequence.*/SEQUENCE, /*** Indicates that the persistence provider must assign * primary keys for the entity using a database identity column.*/IDENTITY, /*** Indicates that the persistence provider should pick an * appropriate strategy for the particular database. The * <code>AUTO</code> generation strategy may expect a database * resource to exist, or it may attempt to create one. A vendor * may provide documentation on how to create such resources * in the event that it does not support schema generation * or cannot create the schema resource at runtime.*/AUTO}
JPA提供的四种标准用法为TABLE, SEQUENCE, IDENTITY, AUTO。
TABLE:使用一个特定的数据库表格来保存主键。
SEQUENCE:根据底层数据库的序列来生成主键,条件是数据库支持序列。
IDENTITY:主键由数据库自动生成(主要是自动增长型) 。
AUTO:主键由程序控制。
详情请查看另外一篇,感觉写的很全,如有兴趣的话,可以看看:https://blog.csdn.net/tree_java/article/details/71158122
本文首发于CSDN,为博主原创文章,如果需要转载,请注明出处,谢谢!
完结!