RE: MyBatis, commit not working

410 views
Skip to first unread message

Poitras Christian

unread,
Mar 21, 2013, 9:30:28 AM3/21/13
to mybati...@googlegroups.com

Hi,

 

Can you send us your mybatis-config.xml file?

What kind of TransactionManager are you using? If you are using managed transactions, then commits done in MyBatis will be ignored and the transaction must be committed by the container.

 

Remember that in a normal application, the SqlSessionFactory is build only once and should be accessible only through some sort of application context. The MyBatis-Guice and MyBatis-Spring plugins may help you here.

 

Christian

 

De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Lautaro Mena
Envoyé : March-20-13 6:02 PM
À : mybati...@googlegroups.com
Objet : MyBatis, commit not working

 

Hello, im starting to use mybatis and i have a problem when i want to commit.

I've created a very simple project in wich i have only a select, an insert and a delete. The mapper file is like this:

 

        <select id="getTags" resultType="hashmap">

                SELECT * FROM TAG

    </select>

    <select id="getTagFromID">

                SELECT * FROM TV_SHOW_TAG WHERE ID = #{ID}

    </select>

    <insert id="addTag" flushCache="false" statementType="PREPARED" useGeneratedKeys="true" keyProperty="ID">

                INSERT INTO TAG(TV_SHOW_ID, TAG, WEB)

                VALUES(#{tvShowID}, #{tag},

                #{web})

    </insert>

    <delete id="removeTag">

                DELETE FROM TAG WHERE ID = #{ID}

    </delete>

 

And when i run the following code:

 

String resource = "mybatis-config.xml";

                Reader inputStream;

                try {

                            inputStream = Resources.getResourceAsReader(resource);

                            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

                            SqlSession session = sqlSessionFactory.openSession();

                            TagMapper mapper = session.getMapper(TagMapper.class);

                            try {

                                        mapper.getTags();

                                        mapper.removeTag(5);

                                        mapper.getTags();

                                        session.commit();

                            } catch (Exception e) {

                                        e.printStackTrace();

                            } finally {

                                        session.close();

                            }

                } catch (IOException e) {

                            e.printStackTrace();

                }

 

I get this log:

 

[18:50:36] DEBUG java.sql.Connection  - ooo Connection Opened

[18:50:36] DEBUG java.sql.PreparedStatement  - ==>  Executing: SELECT * FROM TAG 

[18:50:36] DEBUG java.sql.PreparedStatement  - ==> Parameters: 

[18:50:36] DEBUG java.sql.ResultSet  - <==    Columns: ID, TV_SHOW_ID, WEB, TAG

[18:50:36] DEBUG java.sql.ResultSet  - <==        Row: 5, 12, asd, asd

[18:50:36] DEBUG java.sql.PreparedStatement  - ==>  Executing: DELETE FROM TAG WHERE ID = ? 

[18:50:36] DEBUG java.sql.PreparedStatement  - ==> Parameters: 5(Integer)

[18:50:36] DEBUG java.sql.PreparedStatement  - ==>  Executing: SELECT * FROM TAG 

[18:50:36] DEBUG java.sql.PreparedStatement  - ==> Parameters: 

[18:50:36] DEBUG java.sql.Connection  - xxx Connection Closed

 

 

It looks like is working fine, but if i go to the database the row its still there, the same thing hapend if i run that code again, i've tried setting autocomit in the config file, but its the same.

 

Im using HSQLDB 2.0.0 and MyBatis 3.0.1

 

I would appreciate if someone can help me with this problem.

 

PS: sry for my english... :P

 

Thanks!!!

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Lautaro Mena

unread,
Mar 23, 2013, 11:35:22 AM3/23/13
to mybati...@googlegroups.com
Thanks for the reply Christian!!! the config file is like this:

<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="org.hsqldb.jdbcDriver" />
<property name="url"
value="jdbc:hsqldb:E:\programacion\enviroments\database\db" />
<property name="username" value="SA" />
<property name="password" value="" />
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="mapper.xml" />
</mappers>
</configuration>

And about the SqlSessionFactory im creating it there cause that methos is the main, thats a proyect i've created to try to solve the comit problem. so that its the only instance of SqlSessionFactory that will exist.

Poitras Christian

unread,
Mar 26, 2013, 9:33:51 AM3/26/13
to mybati...@googlegroups.com

Sorry, I overlooked the flushCache attribute you had in your <insert>.

Try setting it to true (default) and see if it works.

 

Christian

 

De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Lautaro Mena
Envoyé : March-23-13 11:35 AM
À : mybati...@googlegroups.com
Objet : Re: MyBatis, commit not working

--

Lautaro Mena

unread,
Apr 11, 2013, 2:33:00 PM4/11/13
to mybati...@googlegroups.com
i've tried to do that, but it is still not working. i do have the option to change to another DB but id love to solve this insted of evoiding this. 

Eduardo Macarron

unread,
Apr 11, 2013, 2:52:18 PM4/11/13
to mybatis-user
Lautaro, are you using 3.0.1 for any reason? Why not the latest?

2013/4/11 Lautaro Mena <laut...@gmail.com>:
> i've tried to do that, but it is still not working. i do have the option to
> change to another DB but id love to solve this insted of evoiding this.
>

Lautaro Mena

unread,
Apr 12, 2013, 3:16:26 PM4/12/13
to mybati...@googlegroups.com
yes, i am using 3.0.1, why? does that release have a problem? i used that cause i just added the maven dependency from a tutorial i found somewhere.

Eduardo Macarron

unread,
Apr 12, 2013, 4:01:44 PM4/12/13
to mybatis-user
https://code.google.com/p/mybatis/issues/list?can=1&q=Component%3DSqlMaps+Version%3DRelease3.x+Type%3DDefect+status%3AFixed

2013/4/12 Lautaro Mena <laut...@gmail.com>:
> yes, i am using 3.0.1, why? does that release have a problem? i used that
> cause i just added the maven dependency from a tutorial i found somewhere.
>

Lautaro Mena

unread,
Apr 15, 2013, 9:01:08 AM4/15/13
to mybati...@googlegroups.com
i just changed the version and it works, thanks.
PS: on this new version the the app its not loggining, does this change with the diferent versions to?

Eduardo Macarron

unread,
Apr 15, 2013, 9:02:59 AM4/15/13
to mybatis-user
Yes, have a look at http://mybatis.github.io/mybatis-3/logging.html

2013/4/15 Lautaro Mena <laut...@gmail.com>:
> i just changed the version and it works, thanks.
> PS: on this new version the the app its not loggining, does this change with
> the diferent versions to?
>

Lautaro Mena

unread,
Apr 15, 2013, 9:23:59 AM4/15/13
to mybati...@googlegroups.com
yes, i am doing that, but i want to logging the info about the operations (querys and results) and i am not being able to do it.. it does correctly log the info about the conectiosn. 

Lautaro Mena

unread,
Apr 15, 2013, 9:31:13 AM4/15/13
to mybati...@googlegroups.com
i wasnt loggining the mapper classes... tnx for the help.

Ted Shaw

unread,
Apr 16, 2013, 9:35:43 AM4/16/13
to mybati...@googlegroups.com
the old version you used  maybe use java.sql as logger name, but new version isn't. there is a new confutation item logPrefix introduced, try to set it to java.sql to get backward compatible, see also http://mybatis.github.io/mybatis-3/configuration.html
Reply all
Reply to author
Forward
0 new messages