ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Niels Beekman" <n.beek...@wis.nl>
Subject RE: java.lang.InstantiationException using Ibatis DAO
Date Mon, 08 Sep 2008 06:56:37 GMT
Your AliasesDaoImpl should have a public constructor that takes a
DaoManager as its single argument. Can you check that this is the case?

 

Hth,

 

Niels

________________________________

From: Paul Ski [mailto:paulski82@hotmail.com] 
Sent: Sunday, September 07, 2008 3:47 AM
To: user-java@ibatis.apache.org
Subject: java.lang.InstantiationException using Ibatis DAO

 

Hi list,
 
Environment:
 
- Windows XP
- Java(TM) SE Runtime Environment (build 1.6.0_10-rc-b28)
- Eclipse Version: 3.4.0 Build id: I20080617-2000
- Ibatis 2.3.0.677
 
Project Jars:
mysql-connector-java-5.1.6-bin.jar
ibatis-2.3.0.677.jar
ibatis-dao-2.jar
 
I've created a class to return me a DaoManager object
 
---snip---
import java.io.Reader;
import com.ibatis.common.resources.Resources;
import com.ibatis.dao.client.DaoManager;
import com.ibatis.dao.client.DaoManagerBuilder;
 
public class DaoManagerMapper
{
 private static final DaoManager daoManager;
 static
 {
  try
  {
   Reader reader = Resources.getResourceAsReader ( "dao.xml" );
   daoManager = DaoManagerBuilder.buildDaoManager ( reader );
  }
  catch ( Exception e )
  {
   throw new RuntimeException (
     "Could not initialize DaoManager. Cause: " + e );
  }
 }
 public static DaoManager getDaoManager ()
 {
  return daoManager;
 }
}
---snip---
 
Test stub to call the code is:
 
---snip---
import com.ibatis.dao.client.DaoManager;
import com.intient.smash.ibatis.Aliases;
import com.intient.smash.ibatis.impl.AliasesDAO;
 
public class TestDaoManagerMapper
{
 public TestDaoManagerMapper ()
 {
  try
  {
   DaoManager daoManager = DaoManagerMapper.getDaoManager ();
   AliasesDAO aliasesDao = (AliasesDAO)daoManager
     .getDao ( AliasesDAO.class );
   try
   {
...
  }
  catch ( Exception e )
  {
   e.printStackTrace ();
  }
 }
 public static void main ( String[] args )
 {
  new TestDaoManagerMapper ();
 }
}
---snip---
 
DAO Config:
 
---snip---
<?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="sqlMapConfig.xml" />
  </transactionManager>
      <!-- DAO interfaces and implementations should be listed here -->
  <dao interface="com.intient.smash.ibatis.impl.AliasesDAO"
   implementation="com.intient.smash.ibatis.impl.AliasesDAOImpl" />
...
 </context>
</daoConfig>
---snip---
 
---snip---
<?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>
 <settings useStatementNamespaces="true" />
 <transactionManager type="JDBC">
  <dataSource type="SIMPLE">
   <property name="JDBC.Driver" value="com.mysql.jdbc.Driver" />
   <property name="JDBC.ConnectionURL"
value="jdbc:mysql://localhost/xxxxxxxx" />
   <property name="JDBC.Username" value="xxxxxxxx" />
   <property name="JDBC.Password" value="xxxxxxxx" />
   <property name="JDBC.DefaultAutoCommit" value="true" />
  </dataSource>
 </transactionManager>
 <sqlMap resource="com/intient/smash/ibatis/maps/aliases_SqlMap.xml" />
...
</sqlMapConfig>
---snip---
 
Exception:
 
---snip---
Exception in thread "main" java.lang.ExceptionInInitializerError
 at
com.intient.smash.TestDaoManagerMapper.<init>(TestDaoManagerMapper.java:
14)
 at
com.intient.smash.TestDaoManagerMapper.main(TestDaoManagerMapper.java:40
)
Caused by: java.lang.RuntimeException: Could not initialize DaoManager.
Cause: com.ibatis.dao.client.DaoException: Error while configuring
DaoManager.  Cause: com.ibatis.dao.client.DaoException: Error
configuring DAO.  Cause: java.lang.InstantiationException:
com.intient.smash.ibatis.impl.AliasesDAOImpl
 at
com.intient.smash.DaoManagerMapper.<clinit>(DaoManagerMapper.java:24)
 ... 2 more
---snip---
 
I can get the SQL Map to work against my database and pull out data but
the above DAO code throws the above exception.
 
Any ideas would be helpful.
 
Thanks,
 
Paul

________________________________

Enter today! Win a Hotmail Go-Kart to race at Bathurst.
<http://www.livelife.ninemsn.com.au/compIntro.aspx?compId=4602> 


Mime
View raw message