Quantcast

MyBatis BatchExecutor insert exception

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

MyBatis BatchExecutor insert exception

Yevgeny Krasik
Hi,

I'm using MyBatis-3.0.6 ,MyBatis-Spring-1.0.2, Spring-3.0.6, MySQL-5.5
and MySQL-connector 5.1.8.

I'm trying to insert a few records using BatchExecutor, but I'm
getting the following exception:
org.apache.ibatis.exceptions.PersistenceException:
### Error committing transaction.  Cause:
org.apache.ibatis.executor.ExecutorException: Error getting generated
key or setting result to parameter object. Cause:
java.lang.NullPointerException
### Cause: org.apache.ibatis.executor.ExecutorException: Error getting
generated key or setting result to parameter object. Cause:
java.lang.NullPointerException
        at
org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:
8)
        at
org.apache.ibatis.session.defaults.DefaultSqlSession.commit(DefaultSqlSession.java:
147)
        at
org.apache.ibatis.session.defaults.DefaultSqlSession.commit(DefaultSqlSession.java:
139)
        at com.user.dao.TempTest.testUsersBatch(TempTest.java:73)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        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.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:
30)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
        at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
68)
        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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:
28)
        at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:
30)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
        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)
Caused by: org.apache.ibatis.executor.ExecutorException: Error getting
generated key or setting result to parameter object. Cause:
java.lang.NullPointerException
        at
org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processAfter(Jdbc3KeyGenerator.java:
65)
        at
org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:
86)
        at
org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:
97)
        at
org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:
92)
        at org.apache.ibatis.executor.BaseExecutor.commit(BaseExecutor.java:
177)
        at
org.apache.ibatis.executor.CachingExecutor.commit(CachingExecutor.java:
80)
        at
org.apache.ibatis.session.defaults.DefaultSqlSession.commit(DefaultSqlSession.java:
144)
        ... 29 more
Caused by: java.lang.NullPointerException
        at java.lang.String$CaseInsensitiveComparator.compare(Unknown Source)
        at java.lang.String$CaseInsensitiveComparator.compare(Unknown Source)
        at java.util.TreeMap.getEntryUsingComparator(Unknown Source)
        at java.util.TreeMap.getEntry(Unknown Source)
        at java.util.TreeMap.get(Unknown Source)
        at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1117)
        at com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:3002)
        at
org.apache.ibatis.type.LongTypeHandler.getNullableResult(LongTypeHandler.java:
17)
        at
org.apache.ibatis.type.LongTypeHandler.getNullableResult(LongTypeHandler.java:
8)
        at
org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:
29)
        at
org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processAfter(Jdbc3KeyGenerator.java:
50)
        ... 35 more

Here is a sample code:

public void testUsersBatch() throws Exception {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("testing-
context.xml");
        SqlSessionFactory factory = ctx.getBean("sqlSessionFactory");
        SqlSession sqlSession = factory.openSession(ExecutorType.BATCH);
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);

        final int numUsers = 10;
        for (int i = 0; i < numUsers; i++) {
                userMapper.insert(new UserImpl("" + i));
        }

        sqlSession.commit();
}

public class UserImpl implements User {
        private String name;

        public UserImpl(String name) {
                this.name = name;
        }

        public String getName() {
                return name;
        }
}

public interface UserMapper {
        public void insert(User user);
}

UserMapper.xml:
<insert id="insert" parameterType="UserImpl" useGeneratedKeys="true"
keyProperty="id">
        INSERT into Users (Name) VALUES (#{name})
</insert>

I know that in Spring I'm supposed to create a SqlSessionTemplate bean
and this is not what I'm doing, but this was supposed to simply be
proof-of-concept. I'm not using a DAO for this reason as well.

Also, I tried using MyBatis-3.1.0-SNAPSHOT and MyBatis-Spring-1.1.0-
SNAPSHOT, and it works on these snapshots.

So, is there any way to make this work until the snapshots are
released?

Thank you,
Yevgeny.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: MyBatis BatchExecutor insert exception

Eduardo Macarron
Yevgeny, could you try 3.1 to see if the problem is fixed?

2012/2/29 Yevgeny Krasik <[hidden email]>:

> Hi,
>
> I'm using MyBatis-3.0.6 ,MyBatis-Spring-1.0.2, Spring-3.0.6, MySQL-5.5
> and MySQL-connector 5.1.8.
>
> I'm trying to insert a few records using BatchExecutor, but I'm
> getting the following exception:
> org.apache.ibatis.exceptions.PersistenceException:
> ### Error committing transaction.  Cause:
> org.apache.ibatis.executor.ExecutorException: Error getting generated
> key or setting result to parameter object. Cause:
> java.lang.NullPointerException
> ### Cause: org.apache.ibatis.executor.ExecutorException: Error getting
> generated key or setting result to parameter object. Cause:
> java.lang.NullPointerException
>        at
> org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:
> 8)
>        at
> org.apache.ibatis.session.defaults.DefaultSqlSession.commit(DefaultSqlSession.java:
> 147)
>        at
> org.apache.ibatis.session.defaults.DefaultSqlSession.commit(DefaultSqlSession.java:
> 139)
>        at com.user.dao.TempTest.testUsersBatch(TempTest.java:73)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>        at java.lang.reflect.Method.invoke(Unknown Source)
>        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.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:
> 30)
>        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
>        at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:
> 68)
>        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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:
> 28)
>        at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:
> 30)
>        at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
>        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)
> Caused by: org.apache.ibatis.executor.ExecutorException: Error getting
> generated key or setting result to parameter object. Cause:
> java.lang.NullPointerException
>        at
> org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processAfter(Jdbc3KeyGenerator.java:
> 65)
>        at
> org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.java:
> 86)
>        at
> org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:
> 97)
>        at
> org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:
> 92)
>        at org.apache.ibatis.executor.BaseExecutor.commit(BaseExecutor.java:
> 177)
>        at
> org.apache.ibatis.executor.CachingExecutor.commit(CachingExecutor.java:
> 80)
>        at
> org.apache.ibatis.session.defaults.DefaultSqlSession.commit(DefaultSqlSession.java:
> 144)
>        ... 29 more
> Caused by: java.lang.NullPointerException
>        at java.lang.String$CaseInsensitiveComparator.compare(Unknown Source)
>        at java.lang.String$CaseInsensitiveComparator.compare(Unknown Source)
>        at java.util.TreeMap.getEntryUsingComparator(Unknown Source)
>        at java.util.TreeMap.getEntry(Unknown Source)
>        at java.util.TreeMap.get(Unknown Source)
>        at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1117)
>        at com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:3002)
>        at
> org.apache.ibatis.type.LongTypeHandler.getNullableResult(LongTypeHandler.java:
> 17)
>        at
> org.apache.ibatis.type.LongTypeHandler.getNullableResult(LongTypeHandler.java:
> 8)
>        at
> org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:
> 29)
>        at
> org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processAfter(Jdbc3KeyGenerator.java:
> 50)
>        ... 35 more
>
> Here is a sample code:
>
> public void testUsersBatch() throws Exception {
>        ApplicationContext ctx = new ClassPathXmlApplicationContext("testing-
> context.xml");
>        SqlSessionFactory factory = ctx.getBean("sqlSessionFactory");
>        SqlSession sqlSession = factory.openSession(ExecutorType.BATCH);
>        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
>
>        final int numUsers = 10;
>        for (int i = 0; i < numUsers; i++) {
>                userMapper.insert(new UserImpl("" + i));
>        }
>
>        sqlSession.commit();
> }
>
> public class UserImpl implements User {
>        private String name;
>
>        public UserImpl(String name) {
>                this.name = name;
>        }
>
>        public String getName() {
>                return name;
>        }
> }
>
> public interface UserMapper {
>        public void insert(User user);
> }
>
> UserMapper.xml:
> <insert id="insert" parameterType="UserImpl" useGeneratedKeys="true"
> keyProperty="id">
>        INSERT into Users (Name)        VALUES (#{name})
> </insert>
>
> I know that in Spring I'm supposed to create a SqlSessionTemplate bean
> and this is not what I'm doing, but this was supposed to simply be
> proof-of-concept. I'm not using a DAO for this reason as well.
>
> Also, I tried using MyBatis-3.1.0-SNAPSHOT and MyBatis-Spring-1.1.0-
> SNAPSHOT, and it works on these snapshots.
>
> So, is there any way to make this work until the snapshots are
> released?
>
> Thank you,
> Yevgeny.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: MyBatis BatchExecutor insert exception

Yevgeny Krasik
Hi Eduardo,

Thanks for the reply. I've already tried with 3.1-SNAPSHOT and it
works, however I prefer not to use a snapshot for production code.
Is there anything else I can do until the snapshot is released?

Best Regards,
Yevgeny.

On Feb 29, 4:54 pm, Eduardo Macarron <[hidden email]>
wrote:

> Yevgeny, could you try 3.1 to see if the problem is fixed?
>
> 2012/2/29 Yevgeny Krasik <[hidden email]>:
>
>
>
>
>
>
>
> > Hi,
>
> > I'm using MyBatis-3.0.6 ,MyBatis-Spring-1.0.2, Spring-3.0.6, MySQL-5.5
> > and MySQL-connector 5.1.8.
>
> > I'm trying to insert a few records using BatchExecutor, but I'm
> > getting the following exception:
> > org.apache.ibatis.exceptions.PersistenceException:
> > ### Error committing transaction.  Cause:
> > org.apache.ibatis.executor.ExecutorException: Error getting generated
> > key or setting result to parameter object. Cause:
> > java.lang.NullPointerException
> > ### Cause: org.apache.ibatis.executor.ExecutorException: Error getting
> > generated key or setting result to parameter object. Cause:
> > java.lang.NullPointerException
> >        at
> > org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactor y.java:
> > 8)
> >        at
> > org.apache.ibatis.session.defaults.DefaultSqlSession.commit(DefaultSqlSessi on.java:
> > 147)
> >        at
> > org.apache.ibatis.session.defaults.DefaultSqlSession.commit(DefaultSqlSessi on.java:
> > 139)
> >        at com.user.dao.TempTest.testUsersBatch(TempTest.java:73)
> >        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> >        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> >        at java.lang.reflect.Method.invoke(Unknown Source)
> >        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.j ava:
> > 42)
> >        at
> > org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.ja va:
> > 20)
> >        at
> > org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:
> > 28)
> >        at
> > org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:
> > 30)
> >        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
> >        at
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.ja va:
> > 68)
> >        at
> > org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.ja va:
> > 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.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:
> > 28)
> >        at
> > org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:
> > 30)
> >        at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
> >        at
> > org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestRe ference.java:
> > 50)
> >        at
> > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:
> > 38)
> >        at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR unner.java:
> > 467)
> >        at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestR unner.java:
> > 683)
> >        at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner .java:
> > 390)
> >        at
> > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunne r.java:
> > 197)
> > Caused by: org.apache.ibatis.executor.ExecutorException: Error getting
> > generated key or setting result to parameter object. Cause:
> > java.lang.NullPointerException
> >        at
> > org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processAfter(Jdbc3KeyGe nerator.java:
> > 65)
> >        at
> > org.apache.ibatis.executor.BatchExecutor.doFlushStatements(BatchExecutor.ja va:
> > 86)
> >        at
> > org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:
> > 97)
> >        at
> > org.apache.ibatis.executor.BaseExecutor.flushStatements(BaseExecutor.java:
> > 92)
> >        at org.apache.ibatis.executor.BaseExecutor.commit(BaseExecutor.java:
> > 177)
> >        at
> > org.apache.ibatis.executor.CachingExecutor.commit(CachingExecutor.java:
> > 80)
> >        at
> > org.apache.ibatis.session.defaults.DefaultSqlSession.commit(DefaultSqlSessi on.java:
> > 144)
> >        ... 29 more
> > Caused by: java.lang.NullPointerException
> >        at java.lang.String$CaseInsensitiveComparator.compare(Unknown Source)
> >        at java.lang.String$CaseInsensitiveComparator.compare(Unknown Source)
> >        at java.util.TreeMap.getEntryUsingComparator(Unknown Source)
> >        at java.util.TreeMap.getEntry(Unknown Source)
> >        at java.util.TreeMap.get(Unknown Source)
> >        at com.mysql.jdbc.ResultSetImpl.findColumn(ResultSetImpl.java:1117)
> >        at com.mysql.jdbc.ResultSetImpl.getLong(ResultSetImpl.java:3002)
> >        at
> > org.apache.ibatis.type.LongTypeHandler.getNullableResult(LongTypeHandler.ja va:
> > 17)
> >        at
> > org.apache.ibatis.type.LongTypeHandler.getNullableResult(LongTypeHandler.ja va:
> > 8)
> >        at
> > org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:
> > 29)
> >        at
> > org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator.processAfter(Jdbc3KeyGe nerator.java:
> > 50)
> >        ... 35 more
>
> > Here is a sample code:
>
> > public void testUsersBatch() throws Exception {
> >        ApplicationContext ctx = new ClassPathXmlApplicationContext("testing-
> > context.xml");
> >        SqlSessionFactory factory = ctx.getBean("sqlSessionFactory");
> >        SqlSession sqlSession = factory.openSession(ExecutorType.BATCH);
> >        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
>
> >        final int numUsers = 10;
> >        for (int i = 0; i < numUsers; i++) {
> >                userMapper.insert(new UserImpl("" + i));
> >        }
>
> >        sqlSession.commit();
> > }
>
> > public class UserImpl implements User {
> >        private String name;
>
> >        public UserImpl(String name) {
> >                this.name = name;
> >        }
>
> >        public String getName() {
> >                return name;
> >        }
> > }
>
> > public interface UserMapper {
> >        public void insert(User user);
> > }
>
> > UserMapper.xml:
> > <insert id="insert" parameterType="UserImpl" useGeneratedKeys="true"
> > keyProperty="id">
> >        INSERT into Users (Name)        VALUES (#{name})
> > </insert>
>
> > I know that in Spring I'm supposed to create a SqlSessionTemplate bean
> > and this is not what I'm doing, but this was supposed to simply be
> > proof-of-concept. I'm not using a DAO for this reason as well.
>
> > Also, I tried using MyBatis-3.1.0-SNAPSHOT and MyBatis-Spring-1.1.0-
> > SNAPSHOT, and it works on these snapshots.
>
> > So, is there any way to make this work until the snapshots are
> > released?
>
> > Thank you,
> > Yevgeny.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: MyBatis BatchExecutor insert exception

Eduardo Macarron
Sorry Yevgeny, but I am afraid there is no workaround.
Loading...