Boa Tarde Pessoal,
Estou tendo problemas para iniciar um projeto simples utilizando o framework ibatis quando tento fazer a query, dá nullpointer no momento que chama o getTransaction, queryForObject(“insert”, usuario);
dá o seguinte erro:
java.lang.NullPointerException
at com.ibatis.dao.engine.impl.StandardDaoManager.getTransaction(StandardDaoManager.java:108)
at com.ibatis.dao.client.template.SqlMapDaoTemplate.getSqlMapExecutor(SqlMapDaoTemplate.java:60)
at com.ibatis.dao.client.template.SqlMapDaoTemplate.queryForObject(SqlMapDaoTemplate.java:162)
at dao.usuario.ibatis.UsuarioDAOIbatisImpl.insert(UsuarioDAOIbatisImpl.java:57)
at facade.usuario.impl.UsuarioIbatisImpl.insert(UsuarioIbatisImpl.java:60)
at main.PocIbatisMain.main(PocIbatisMain.java:28)
o meu dao.xml é o seguinte:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE daoConfig
PUBLIC "-//ibatis.apache.org//DTD DAO Configuration 2.0//EN"
"http://ibatis.apache.org/dtd/dao-2.dtd">
<daoConfig>
<context>
<transactionManager type="SQLMAP">
<property name="SqlMapConfigResource"
value="dao/sql-map-config.xml"/>
</transactionManager>
<dao interface="dao.usuario.UsuarioDAO"
implementation="dao.usuario.ibatis.UsuarioDAOIbatisImpl"/>
</context>
</daoConfig>
este é o meu sql-map-config.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<properties resource="properties/database.properties"/>
<settings cacheModelsEnabled="true" enhancementEnabled="true" lazyLoadingEnabled="true" errorTracingEnabled="false" maxRequests="32" maxSessions="10" maxTransactions="5" useStatementNamespaces="false" />
<transactionManager type="JDBC">
<dataSource type="SIMPLE">
<property value="${driver}" name="JDBC.Driver"/>
<property value="${url}" name="JDBC.ConnectionURL"/>
<property value="${username}" name="JDBC.Username"/>
<property value="${password}" name="JDBC.Password"/>
</dataSource>
</transactionManager>
<sqlMap resource="dao/usuario/ibatis/Usuario.xml"/>
</sqlMapConfig>
este é o meu DaoConfig:
public class DaoConfig {
private static final String resource = "dao/dao.xml";
private static final DaoManager daoManager;
static {
try {
daoManager = newDaoManager(null);
Properties props = Resources.getResourceAsProperties("properties/database.properties");
String url = props.getProperty("url");
String driver = props.getProperty("driver");
String username = props.getProperty("username");
String password = props.getProperty("password");
if (url.equals("jdbc:mysql://localhost/Poc1")) {
Class.forName(driver).newInstance();
Connection conn = DriverManager.getConnection(url, username, password);
conn.close();
}
} catch (Exception e) {
throw new RuntimeException("Description. Cause: " + e, e);
}
}
public static DaoManager getDaoManager() {
return daoManager;
}
public static DaoManager newDaoManager(Properties props) {
try {
Reader reader = Resources.getResourceAsReader(resource);
return DaoManagerBuilder.buildDaoManager(reader, props);
} catch (Exception e) {
throw new RuntimeException(
"Could not initialize DaoConfig. Cause: " + e, e);
}
}
}
este é o Usuario.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Usuario">
<typeAlias alias="usuario" type="modelo.usuario.Usuario" />
<insert id="insert" parameterClass="usuario">
INSERT INTO USUARIO (NOME, SOBRENOME, LOGIN, SENHA)
VALUES (#nome#, #sobrenome#, #login#, #senha#)
</insert>
</sqlMap>
e a classe que implementa o meu dao:
public class UsuarioDAOIbatisImpl extends SqlMapDaoTemplate implements UsuarioDAO {
public UsuarioDAOIbatisImpl(DaoManager daoManager) {
super(daoManager);
}
@Override
public void insert(Usuario usuario) {
try {
daoManager.startTransaction();
queryForObject("insert", usuario);
daoManager.commitTransaction();
} catch (Exception e) {
System.err.println("ERRO:" + e.getMessage());
e.printStackTrace();
} finally {
daoManager.endTransaction();
}
}
}
será que alguem poderia me ajudar? desde já obrigado pessoal.