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.
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
--