MyBatis returns the self-increment ID after inserting data into the Oracle database

Source: Internet
Author: User

1. Set the ID as a self-increment sequence

CREATE OR REPLACE TRIGGER "Datalib". " Trig_user_add "
Before INSERT on ' Sys_user ' for each row
Begin
Select Seq_user.nextval into:new. " USER_ID "from dual;
End
ALTER TRIGGER "Datalib". " Trig_user_add "ENABLE;

XML configuration file about the database in 2.mybatis

<insert id= "Save" parametertype= "Io.renren.entity.SysUserEntity" keyproperty= "userId" databaseid= "Oracle" >
<selectkey keyproperty= "UserId" resulttype= "Long" order= "before" >
Select Seq_user. Nextval from dual
</selectKey>
INSERT INTO "Sys_user"
(
"Username",
"Password",
"Email",
"Mobile",
"Status",
"Create_time"
)
Values
(
#{username, Jdbctype=varchar},
#{password, Jdbctype=varchar},
#{email, Jdbctype=varchar},
#{mobile, Jdbctype=varchar},
#{status, Jdbctype=numeric},
#{createtime, Jdbctype=date}
)
</insert>

3. Test code

Sysuserentity user=new sysuserentity ();
User.setusername (username);
User.setpassword (passwd);
User.setemail (email);
User.setmobile (mobile);
User.setstatus (status);
System.out.println (User.getuserid () + "888888888888888888888888");
Sysuserservice.save (user);

System.out.println (User.getuserid () + "=========================");

MyBatis returns the self-increment ID after inserting data into the Oracle database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.