Home > Back-end > Mybatis at insert time, back to the main key type should automatically be strong to Long
Mybatis at insert time, back to the main key type should automatically be strong to Long
Time:01-12
important discovery, studies the one afternoon
Found that if the call dao an insert operation, return on the primary key in the assignment to DO object id attributes, but the id of the object is for Integer types, the return value is forcibly assignment into Long, and the id is of type Integer gives actually became a Long value, is terrible, can't make any for the value of the operation, Otherwise will be submitted to the Java. Lang. Long always be cast to Java. Lang, Integer, and in the mapping file, will return to the insert statement on the id mapping in the object, the other members of the type Integer, also will not be strong, when I want to insert now to obtain primary key id then assignment on the id attribute of object, but of type Integer, may god grant called
CodePudding user response:
What database, and what is the primary key access, stick your mapping file
CodePudding user response:
The mysql database when no class mapping this is inserted into the keyProperty separate mapping to the id field
CodePudding user response:
These graphs
CodePudding user response:
UseGenerateKeys is to use mysql on the primary key, return is Long, if you want to change the type, you can use custom primary keys, like oracle, can define resultType
CodePudding user response:
Don't agree with this point of view, I has already demonstrated that if useGenerateKeys mapping field name is not id, type Integer, as mapping can succeed, and mapping out the value is an Integer, not to be strong to Long
CodePudding user response:
See your BOssDo about id set inside, the get method, the parameter is what type, and your figure inside an id value is 1, how to figure 2 into long 18 in it? Feeling which part you write wrong
CodePudding user response:
Feeling problems out on your BossDo entity class, complete code stick out and have a look
CodePudding user response:
The database id of the type and length is how much, if there is any more than in Java Integer range
CodePudding user response:
Figure 1 is 1, it is my first sentence manual assignment 1, prove that he is an Integer, originally for the sake of contrast, and behind set and get no problem, check the countless times, otherwise figure 1 also does not show is an Integer