更新时间:2023-11-14 22:59:58
您可以通过使用根据当前DBMS定义的属性来做到这一点.
You can do this by using properties that are defined depending on the current DBMS.
<property name="uuid_type" value="uuid" dbms="postgresql"/>
<property name="uuid_type" value="uniqueidentifier" dbms="mssql"/>
<property name="uuid_type" value="RAW(16)" dbms="oracle"/>
<property name="uuid_function" value="uid.uuid_generate_v4()" dbms="postgresql"/>
<property name="uuid_function" value="NEWID()" dbms="mssql"/>
<property name="uuid_function" value="sys_guid()" dbms="oracle"/>
然后在定义表时使用这些属性:
Then use those properties when defining the table:
<column name="id" type="${uuid_type}" defaultValueComputed="${uuid_function}">
<constraints nullable="false" unique="true" />
</column>
请注意,您需要使用 defaultValueComputed
,不 value
Note that you need to use defaultValueComputed
, not value
如果该列是使用默认值定义的,则将其保留在插入语句中,然后数据库将在插入时生成UUID.
If the column is defined with a default value, just leave it out in your insert statements and the database will then generate the UUID when inserting.