title: mybatis's java data type for auto generated key
body: <p>I want to insert Post domain into MySQL db.</p>
  
  <p>Post domain is like this:</p>
  
  <pre><code>public class Post {
      private long postId;
      private String title;
      String content;
      private String pictureId;
      private Picture picture;
      private int authorId;   
      private User author;
      private Date postTime;
      private int status;
      private int commentCount;
  </code></pre>
  
  <p>}</p>
  
  <p>The db table is created like this:</p>
  
  <pre><code>CREATE TABLE `tb_posts` (
  `post_id` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL,
  `content` varchar(2000) COLLATE utf8_unicode_ci DEFAULT NULL,
  `picture_id` varchar(250) COLLATE utf8_unicode_ci DEFAULT NULL,
  `author_id` int(11) DEFAULT NULL,
  `post_time` datetime DEFAULT NULL,
  `status` int(11) DEFAULT NULL,
  `comment_count` int(11) DEFAULT NULL,
  PRIMARY KEY (`post_id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  </code></pre>
  
  <p>The mybatis mapper is like this:</p>
  
  <pre><code>&lt;insert id="insert" parameterType="post"&gt;
  
      INSERT INTO tb_posts
      (
          title, content, picture_id, author_id, post_time, status, comment_count
      ) VALUES
      (
          #{title}, #{content}, #{pictureId}, #{authorId}, #{postTime}, #{status}, #{commentCount}
      )
      &lt;selectKey keyProperty="postId" resultType="long" order="BEFORE"&gt;
      SELECT LAST_INSERT_ID() AS postId;
      &lt;/selectKey&gt;
  &lt;/insert&gt;
  </code></pre>
  
  <p>I wonder why the generated key which name is "postId" always has exception which is "java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long"</p>
  
  <p>The whole exception is like this:</p>
  
  <pre><code>java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Long
  at $Proxy14.insert(Unknown Source)
  at me.joyo.mate.core.service.impl.PostServiceImpl.insert(PostServiceImpl.java:44)
  at me.joyo.mate.core.test.PostTester.insert(PostTester.java:50)
  at me.joyo.mate.core.test.PostTester.test(PostTester.java:33)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
  at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
  at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
  at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
  at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
  at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
  at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
  at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
  at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
  at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  </code></pre>
  
  <p>help please !!</p>