我的表插件只有两列:ID 和 DTYPE。我想在 DTYPE 列中存储一个字符串。ID 应该自动递增并由 insert 方法返回。为此,我像这样手动创建了“id_sequence”:
CREATE SEQUENCE id_sequence
INCREMENT 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1
CACHE 1;
OWNED BY plugin.id;
这是我的 mapper.xml 文件:
<insert id="insert" useGeneratedKeys="true" parameterType="String">
<selectKey keyProperty="id" resultType="int" order="BEFORE">
SELECT CAST(nextval('id_sequence') as INTEGER)
</selectKey>
INSERT INTO plugins (ID, DTYPE)
VALUES ( #{id}, #{plugin})
RETURNING ID;
</insert>
和相应的mapper.java:
int insert(String plugin);
问题陈述:1)我无法获得正确的 ID 值(它为空),2)我得到一个错误
SQL: INSERT INTO public.ucpoplugin (ID, DTYPE) VALUES ( ?, CORRECT_STRING)
Cause: org.postgresql.util.PSQLException: FEHLER: Column »id« is of type bigint, but the sentence is has Type character varying.