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 vishalj <Vi...@ivycomptech.com> on 2009/12/30 06:28:49 UTC

New to iBatis facing problem to get started

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


Re: New to iBatis facing problem to get started

Posted by Clinton Begin <cl...@gmail.com>.
You can sort of tell given his output:

    *PROFILE null*
    Exception in thread "main" java.lang.NullPointerException
           at Main.main(Main.java:23)

So given that:

21.    ...
22.    System.out.println(*"PROFILE " + profile*);
23.    System.out.println(profile.getName());
24.    ...

We take NPE very seriously, and consider any NPE thrown by iBATIS to be a
but.  This however, is not being thrown by iBATIS.  There is simply no
profile object returned, and he's calling getName() against a null
reference.

Clinton

On Wed, Dec 30, 2009 at 10:38 PM, Guy Rouillier <gu...@burntmail.com>wrote:

> On 12/30/2009 12:28 AM, vishalj wrote:
>
>>
>> Hi,
>> I am using iBatis for the first time ,but no success yet.This is how my
>> setup looks like
>>
> ...
>
>  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)
>>
>
> Well, put in a catch clause and print a stack trace.  Hard to tell where
> the error is occurring, since you are not showing complete source, so we
> have no idea where line 23 is.
>
> Though the execution is printing out your first System.out, I'm guessing
> the error is much earlier.  My guess would be that it can't find your
> Configuration.xml file.  Are your running within an IDE?  Debug and single
> step through to make sure that the factory, session and mapper objects are
> all getting created successfully.
>
> --
> Guy Rouillier
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

Re: New to iBatis facing problem to get started

Posted by Guy Rouillier <gu...@burntmail.com>.
On 12/30/2009 12:28 AM, vishalj wrote:
>
> Hi,
> I am using iBatis for the first time ,but no success yet.This is how my
> setup looks like
...
> 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)

Well, put in a catch clause and print a stack trace.  Hard to tell where 
the error is occurring, since you are not showing complete source, so we 
have no idea where line 23 is.

Though the execution is printing out your first System.out, I'm guessing 
the error is much earlier.  My guess would be that it can't find your 
Configuration.xml file.  Are your running within an IDE?  Debug and 
single step through to make sure that the factory, session and mapper 
objects are all getting created successfully.

-- 
Guy Rouillier

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


Re: New to iBatis facing problem to get started

Posted by vishalj <Vi...@ivycomptech.com>.
Thanks for the replies its working now .

Clinton Begin wrote:
> 
> Well... I don't know what to tell you.  iBATIS isn't reporting an error,
> and
> doesn't often fail silently (if ever).  You can try turning on logging and
> replace your main method with a unit test that has assertions like
> assertNotNull(userProfile);, which is cleaner than letting an NPE occur.
> 
> Clinton
> 
> On Wed, Dec 30, 2009 at 2:18 AM, vishalj <Vi...@ivycomptech.com> wrote:
> 
>>
>> tha db table contains a row with id vakue of '1' which i am trying to
>> query
>> .And also the same select statement is working fine
>>
>> Clinton Begin wrote:
>> >
>> > The NPE is coming from your main method (profile.getName()).  It's not
>> > finding the profile record. It looks like iBATIS is working, but
>> there's
>> > simply no data to be found, or the parameter is incorrect.
>> >
>> > Clinton
>> >
>> > On Tue, Dec 29, 2009 at 10:28 PM, vishalj <Vi...@ivycomptech.com>
>> wrote:
>> >
>> >>
>> >> 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
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/New-to-iBatis-facing-problem-to-get-started-tp26964254p26965432.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
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/New-to-iBatis-facing-problem-to-get-started-tp26964254p27010974.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


Re: New to iBatis facing problem to get started

Posted by vishalj <Vi...@ivycomptech.com>.
Hi,
does my configuration looks incorrect somewhere 


Clinton Begin wrote:
> 
> Well... I don't know what to tell you.  iBATIS isn't reporting an error,
> and
> doesn't often fail silently (if ever).  You can try turning on logging and
> replace your main method with a unit test that has assertions like
> assertNotNull(userProfile);, which is cleaner than letting an NPE occur.
> 
> Clinton
> 
> On Wed, Dec 30, 2009 at 2:18 AM, vishalj <Vi...@ivycomptech.com> wrote:
> 
>>
>> tha db table contains a row with id vakue of '1' which i am trying to
>> query
>> .And also the same select statement is working fine
>>
>> Clinton Begin wrote:
>> >
>> > The NPE is coming from your main method (profile.getName()).  It's not
>> > finding the profile record. It looks like iBATIS is working, but
>> there's
>> > simply no data to be found, or the parameter is incorrect.
>> >
>> > Clinton
>> >
>> > On Tue, Dec 29, 2009 at 10:28 PM, vishalj <Vi...@ivycomptech.com>
>> wrote:
>> >
>> >>
>> >> 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
>> >>
>> >>
>> >
>> >
>>
>> --
>> View this message in context:
>> http://old.nabble.com/New-to-iBatis-facing-problem-to-get-started-tp26964254p26965432.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
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/New-to-iBatis-facing-problem-to-get-started-tp26964254p27010870.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


Re: New to iBatis facing problem to get started

Posted by Clinton Begin <cl...@gmail.com>.
Well... I don't know what to tell you.  iBATIS isn't reporting an error, and
doesn't often fail silently (if ever).  You can try turning on logging and
replace your main method with a unit test that has assertions like
assertNotNull(userProfile);, which is cleaner than letting an NPE occur.

Clinton

On Wed, Dec 30, 2009 at 2:18 AM, vishalj <Vi...@ivycomptech.com> wrote:

>
> tha db table contains a row with id vakue of '1' which i am trying to query
> .And also the same select statement is working fine
>
> Clinton Begin wrote:
> >
> > The NPE is coming from your main method (profile.getName()).  It's not
> > finding the profile record. It looks like iBATIS is working, but there's
> > simply no data to be found, or the parameter is incorrect.
> >
> > Clinton
> >
> > On Tue, Dec 29, 2009 at 10:28 PM, vishalj <Vi...@ivycomptech.com>
> wrote:
> >
> >>
> >> 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
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/New-to-iBatis-facing-problem-to-get-started-tp26964254p26965432.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
>
>

Re: New to iBatis facing problem to get started

Posted by vishalj <Vi...@ivycomptech.com>.
tha db table contains a row with id vakue of '1' which i am trying to query
.And also the same select statement is working fine 

Clinton Begin wrote:
> 
> The NPE is coming from your main method (profile.getName()).  It's not
> finding the profile record. It looks like iBATIS is working, but there's
> simply no data to be found, or the parameter is incorrect.
> 
> Clinton
> 
> On Tue, Dec 29, 2009 at 10:28 PM, vishalj <Vi...@ivycomptech.com> wrote:
> 
>>
>> 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
>>
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/New-to-iBatis-facing-problem-to-get-started-tp26964254p26965432.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


Re: New to iBatis facing problem to get started

Posted by Clinton Begin <cl...@gmail.com>.
The NPE is coming from your main method (profile.getName()).  It's not
finding the profile record. It looks like iBATIS is working, but there's
simply no data to be found, or the parameter is incorrect.

Clinton

On Tue, Dec 29, 2009 at 10:28 PM, vishalj <Vi...@ivycomptech.com> wrote:

>
> 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
>
>