【第一章 Design】 7 主键生成详细步骤
什么是自动生成列Many databases allow users to define special columns with values that are automatically created by the the database to be unique for each inserted row. Main use if this feature is to generate a primary key. Such columns are often called "autoincrement" or "identity" columns. JDBC3 specification provides Java API to read values of such columns right after an insert is performed. JDBC calls such columns "generated keys",and Cayenne follows JDBC in that. Namely DbAttribute has a "generated" boolean property to indicate that a given column value is provided by the database on insert. ? ? 在Cayenne指定自动生成列主键生成是Cayenne中自动生成列的唯一应用。 ? If a primary key column is marked as "generated" in CayenneModeler (see below),Cayenne will bypass its default PK generation mechanism and rely on the database to provide a key value. But only if the runtime DbAdapter is configured to allow that (see "Hints and Limitations" section for explanation). Currently only Derby,MySQL and SQLServer adapters allow generated columns by default. For the rest of the adapters,Cayenne will fall back to its default PK generation mechanism. ? 如果你的驱动支持自动生成API,但是在Cayenne中没有开启,可以手动开启: 在 CayenneModeler中,每个DbEntity 有独立的主键自动生成配置:
?
? ? ?
|