You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Rashmi Dave <ra...@persistent.co.in> on 2006/01/20 17:02:55 UTC
NPE with iBATIS - queryForObject
We have used ABATOR to generate DAO classes for tables in Oracle.
The SQLMap.xml generated by abator is unchanged. I have the following
daoconfig
<daoConfig>
<context id="sqlmap">
<transactionManager type="SQLMAP">
<property name="SqlMapConfigResource" value=
"com/eobone/uam/dblayer/impl/sqlmap/EOBNE_USERS_SqlMap.xml"/>
</transactionManager>
<dao interface="com.uam.dblayer.dao.UsersDAO"
implementation=
"com.uam.dblayer.dao.UsersDAOImpl"/>
</context>
</daoConfig>
Code to call this
// TODO Auto-generated method stub
Reader reader=
Resources.getResourceAsReader("daoConfig.xml");
daoManager =
DaoManagerBuilder.buildDaoManager(reader);
usersdao = new UsersDAOImpl(daoManager);
UsersKey ukey = new UsersKey();
ukey.setUserId(new BigDecimal(1));
Users users = null;
users = usersdao.selectByPrimaryKey(ukey);
The exception occurs at the selectByPrimaryKey. I am not sure what is wrong.
Any pointers on this please ASAP would be very helpful.
TIA
~Rashmi
RE: NPE with iBATIS - queryForObject
Posted by Rashmi Dave <ra...@persistent.co.in>.
Thanks so much for this Jeff. Sadly, I am new to both Java and iBATIS. I am
learning though.
This is working now.
:-)
~Rashmi
_____
From: Jeff Butler [mailto:jeffgbutler@gmail.com]
Sent: Friday, January 20, 2006 10:26 PM
To: user-java@ibatis.apache.org
Subject: Re: NPE with iBATIS - queryForObject
You are not accessing the DAO correctly (see the DAO manual, page 8). This
is the proper way to gain access to a DAO implementation with iBATIS DAO:
UsersDAO usersdao = daoManager.getDao(UsersDAO.class);
If you still have a problem after making this fix, then please send more
specifics about the problem.
Jeff Butler
P.S. - a good rule of thumb in Java is that you should never use "new" with
any class that has "Impl" in the name. "Impl" is a good indication that
there is a factory somewhere that is responsible for creating the object.
On 1/20/06, Rashmi Dave <ra...@persistent.co.in> wrote:
We have used ABATOR to generate DAO classes for tables in Oracle.
The SQLMap.xml generated by abator is unchanged. I have the following
daoconfig
<daoConfig>
<context id="sqlmap">
<transactionManager type="SQLMAP">
<property name="SqlMapConfigResource" value=
"com/eobone/uam/dblayer/impl/sqlmap/EOBNE_USERS_SqlMap.xml"/>
</transactionManager>
<dao interface="com.uam.dblayer.dao.UsersDAO"
implementation=
"com.uam.dblayer.dao.UsersDAOImpl"/>
</context>
</daoConfig>
Code to call this
// TODO Auto-generated method stub
Reader reader=
Resources.getResourceAsReader("daoConfig.xml");
daoManager =
DaoManagerBuilder.buildDaoManager (reader);
usersdao = new UsersDAOImpl(daoManager);
UsersKey ukey = new UsersKey();
ukey.setUserId(new BigDecimal(1));
Users users = null;
users = usersdao.selectByPrimaryKey(ukey);
The exception occurs at the selectByPrimaryKey. I am not sure what is wrong.
Any pointers on this please ASAP would be very helpful.
TIA
~Rashmi
Re: NPE with iBATIS - queryForObject
Posted by Jeff Butler <je...@gmail.com>.
You are not accessing the DAO correctly (see the DAO manual, page 8). This
is the proper way to gain access to a DAO implementation with iBATIS DAO:
UsersDAO usersdao = daoManager.getDao(UsersDAO.class);
If you still have a problem after making this fix, then please send more
specifics about the problem.
Jeff Butler
P.S. - a good rule of thumb in Java is that you should never use "new" with
any class that has "Impl" in the name. "Impl" is a good indication that
there is a factory somewhere that is responsible for creating the object.
On 1/20/06, Rashmi Dave <ra...@persistent.co.in> wrote:
>
> We have used ABATOR to generate DAO classes for tables in Oracle.
> The SQLMap.xml generated by abator is unchanged. I have the following
> daoconfig
>
> <daoConfig>
> <context id="sqlmap">
> <transactionManager type="SQLMAP">
> <property name="SqlMapConfigResource" value=
> "com/eobone/uam/dblayer/impl/sqlmap/EOBNE_USERS_SqlMap.xml"/>
> </transactionManager>
> <dao interface="com.uam.dblayer.dao.UsersDAO"
> implementation=
> "com.uam.dblayer.dao.UsersDAOImpl"/>
> </context>
> </daoConfig>
>
>
>
> Code to call this
>
> // TODO Auto-generated method stub
> Reader reader=
> Resources.getResourceAsReader("daoConfig.xml");
> daoManager =
> DaoManagerBuilder.buildDaoManager(reader);
> usersdao = new UsersDAOImpl(daoManager);
> UsersKey ukey = new UsersKey();
> ukey.setUserId(new BigDecimal(1));
> Users users = null;
> users = usersdao.selectByPrimaryKey(ukey);
>
> The exception occurs at the selectByPrimaryKey. I am not sure what is
> wrong.
> Any pointers on this please ASAP would be very helpful.
>
> TIA
>
> ~Rashmi
>
>