<version>5.1.9</version>
</dependency>
<dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.17</version>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.7.5</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.17</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib</artifactId>
+ <version>2.2.2</version>
</dependency>
</dependencies>
</project>
import de.example.mybatis.model.Ad;
import de.example.mybatis.repository.mapper.AdMapper;
-//import de.example.ibatis.demo.dao.UserDao;
-//import de.example.ibatis.demo.dao.UserDaoIbatis;
-//import de.example.ibatis.dto.UserTEO;
public class TestMain {
// EN EL CLASSPATH:
final SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder()
.build(/**TestMain.class.getResourceAsStream("sql-maps-config.xml")**/
- Resources.getResourceAsStream("mybatis-sql-maps-config.xml"));
+ Resources.getResourceAsStream("mybatis-sql-maps-config.xml"), "mybatisexample");
final SqlSession session = sqlSessionFactory.openSession();
// EN MYBATIS HAY UNA FORMA MEJOR QUE ESTA
// try {
// session.close();
// }
// ESTA FORMA ES MUCHO MEJOR :)
+
try {
final AdMapper mapper = session.getMapper(AdMapper.class);
final Ad adprueba = new Ad();
+ adprueba.setAdMobileImage("lol");
adprueba.setCompanyCategId(200L);
adprueba.setCreatedAt(new Date());
adprueba.setCompanyId(2L);
adprueba.setUpdatedAt(new Date());
mapper.insert(adprueba);
+ session.commit();
// Ad ad = mapper.selectByPrimaryKey(1000L);
} finally {
session.close();
}
-
- // De esa forma consigo que el encoding dependa del valor puesto en la cabecera del xml :)
-
- // SqlSession session = sqlSessionFactory.openSession();
- // try {
- // Blog blog = session.selectOne("org.mybatis.example.BlogMapper.selectBlog", 101);
- // } finally {
- // session.close();
- // }
- //
- // SqlSession session = sqlSessionFactory.openSession();
- // try {
- // BlogMapper mapper = session.getMapper(BlogMapper.class);
- // Blog blog = mapper.selectBlog(101);
- // } finally {
- // session.close();
- // }
- // SqlMapClient sqlmapClient = SqlMapClientBuilder.buildSqlMapClient (reader);
- //
- // //Create a new user to persist
- // UserTEO user = new UserTEO();
- // user.setId(1);
- // user.setName("Demo User");
- // user.setPassword("password");
- // user.setEmail("demo-user@howtodoinjava.com");
- // user.setStatus(1);
- //
- // //Add the user
- // manager.addUser(user,sqlmapClient);
- //
- // //Fetch the user detail
- // UserTEO createdUser = manager.getUserById(4, sqlmapClient);
- // System.out.println(createdUser.getEmail());
- //
- // //Lets delete the user
- // manager.deleteUserById(1, sqlmapClient);
- // try {
- // Thread.sleep(100000);
- // } catch (InterruptedException e) {
- // // TODO Auto-generated catch block
- // e.printStackTrace();
- // }
}
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
+<log4j:configuration>
+ <appender name="stdout" class="org.apache.log4j.ConsoleAppender">
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L %m%n"/>
+ </layout>
+ </appender>
+ <root>
+ <priority value="debug"></priority>
+ <appender-ref ref="stdout"/>
+ </root>
+</log4j:configuration>
\ No newline at end of file
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
+
<configuration>
- <environments default="development">
- <environment id="development">
+<settings>
+ <setting name="cacheEnabled" value="false"/>
+ <setting name="lazyLoadingEnabled" value="false"/>
+ <setting name="aggressiveLazyLoading" value="false"/>
+ <setting name="multipleResultSetsEnabled" value="true"/>
+ <setting name="useColumnLabel" value="false"/>
+ <setting name="useGeneratedKeys" value="false"/>
+ <setting name="autoMappingBehavior" value="PARTIAL"/>
+ <setting name="defaultExecutorType" value="SIMPLE"/>
+ <setting name="defaultStatementTimeout" value="5"/>
+ <setting name="safeRowBoundsEnabled" value="false"/>
+ <setting name="mapUnderscoreToCamelCase" value="false"/>
+ <setting name="localCacheScope" value="SESSION"/>
+ <setting name="jdbcTypeForNull" value="OTHER"/>
+ <setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString"/>
+ <setting name="logPrefix" value="mybatislogger"/>
+ <setting name="logImpl" value="LOG4J"/>
+ <setting name="proxyFactory" value="CGLIB"/>
+ </settings>
+ <environments default="mybatisexample">
+ <environment id="mybatisexample">
<transactionManager type="JDBC"/>
- <dataSource type="POOLED">
+ <dataSource type="UNPOOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
- <property name="url" value="jdbc:mysql://localhost:3306/mybatis_example"/>
+ <property name="url" value="jdbc:mysql://localhost:3306/mybatis_example?characterEncoding=UTF-8"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</dataSource>