ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vishalj <Vish...@ivycomptech.com>
Subject New to iBatis facing problem to get started
Date Wed, 30 Dec 2009 05:28:49 GMT

Hi,
I am using iBatis for the first time ,but no success yet.This is how my
setup looks like

DB SCHEMA:
  CREATE TABLE TEST_USERPROFILE
   (	NAME VARCHAR2(20), 
	ID NUMBER
   ) ;

iBatis configuration.xml
<configuration>
	<properties resource="com/pg/ibatis/config/config.properties"></properties>
	<typeAliases>
		<typeAlias type="com.pg.beans.UserProfile" alias="UserProfile"/>
	</typeAliases>
	<environments default="development">
		<environment id="development">
			<transactionManager type="JDBC" />
			<dataSource type="POOLED">
				<property name="driver" value="${driver}" />
				<property name="url" value="${url}" />
				<property name="username" value="${username}" />
				<property name="password" value="${password}" />
			</dataSource>
		</environment>
	</environments>
	<mappers>
			<mapper resource="com/pg/ibatis/config/UserProfileMapper.xml" />
	</mappers>
</configuration>

UserProfileMapper.xml
<mapper namespace="com.pg.mappers.UserProfileMapper">
	<select id="selectUserProfile" parameterType="int"
resultType="UserProfile">
		SELECT * FROM TEST_USERPROFILE WHERE id=#{id}
</select>
</mapper>

UserProfileMapper.java
public interface UserProfileMapper {		
	UserProfile selectUserProfile(int id);
}

UserProfile.java
public class UserProfile {	
	String name;	
	int id;
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}

}

Main method 
String resource = "com/pg/ibatis/config/Configuration.xml";
		Reader reader = Resources.getResourceAsReader(resource);
		SqlSessionFactory factory = new SqlSessionFactoryBuilder()
				.build(reader);
		SqlSession session = factory.openSession();
		try {
			UserProfileMapper mapper = session.getMapper(UserProfileMapper.class);
			UserProfile profile = mapper.selectUserProfile(1);
			System.out.println("PROFILE " + profile);
			System.out.println(profile.getName());
		} finally {
			session.close();
		}

But i am getting NPE 
PROFILE null
Exception in thread "main" java.lang.NullPointerException
	at Main.main(Main.java:23)
-- 
View this message in context: http://old.nabble.com/New-to-iBatis-facing-problem-to-get-started-tp26964254p26964254.html
Sent from the iBATIS - User - Java mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org


Mime
View raw message