Does ibatis support Constructor with arguments?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Does ibatis support Constructor with arguments?

jaggernat12345
hi guys

Is it a MUST that my resultClass have a no -arg constructor ?

I have been struggling whole day resolving this issue. I am using Spring with Ibatis. This is my complete code.


I have in my xml file

------------------------------------------
<typeAlias alias ="userInfo" type ="nj.ado.UserInformation"/>

<select id ="my.query" resultClass="userInfo" parameterclass="java.lang.String">
select A.username,A.Id from User A where A.username= #username:CHAR#
</select>
-------------------------------------------


This is my UserInformation.java

----------------------------------------
public class UserInformation extends org.springframework.security.userdetails.User
{
public String accountId = null;
public UserInformation(String username,String password,boolean enabled,GrantedAuthority[]
  authorities, String accountId) throws IllegalArgumentException
        {
        super(username,password,enabled,authorities); // calls superclass constructor
        this.accountId = accountId;
        }
setAccountId();
getAccountId();
}
-------------------------------------

This is how i am calling the query
----------------------------------------------
UserInformation ui = (UserInformation)SqlMapClientTemplate.queryForObject("my.query" , username);
------------------------------------------------

pretty straightforward.

AND this is the error i get
>>>>
InstantiationException. UserInformation canot be instantiated

I am assuming it is because i dont have a no argument constructor in UserInformation.java ? Is that the problem?

PS: I cannot have a no argument constructor in UserInformation.java because spring doesnt allow me to do that.

Any help would be greatly greatly appreciated

thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Does ibatis support Constructor with arguments?

rd_djunaedi
hi jaggernat12345 ,
im not so sure if ibatis does (or doesnt) support your case, but why dont you add a no-argument constructor?

Is there any reason why you dont do that?
 
hi guys

Is it a MUST that my resultClass have a no -arg constructor ?

I have been struggling whole day resolving this issue. I am using Spring with Ibatis. This is my complete code.


I have in my xml file

------------------------------------------
<typeAlias alias ="userInfo" type ="nj.ado.UserInformation"/>

<select id ="my.query" resultClass="userInfo" parameterclass="java.lang.String">
select A.username,A.Id from User A where A.username= #username:CHAR#
</select>
-------------------------------------------


This is my UserInformation.java

----------------------------------------
public class UserInformation extends org.springframework.security.userdetails.User
{
public String accountId = null;
public UserInformation(String username,String password,boolean enabled,GrantedAuthority[]
  authorities, String accountId) throws IllegalArgumentException
        {
        super(username,password,enabled,authorities); // calls superclass constructor
        this.accountId = accountId;
        }
setAccountId();
getAccountId();
}
-------------------------------------

This is how i am calling the query
----------------------------------------------
UserInformation ui = (UserInformation)SqlMapClientTemplate.queryForObject("my.query" , username);
------------------------------------------------

pretty straightforward.

AND this is the error i get
>>>>
InstantiationException. UserInformation canot be instantiated

I am assuming it is because i dont have a no argument constructor in UserInformation.java ? Is that the problem?

PS: I cannot have a no argument constructor in UserInformation.java because spring doesnt allow me to do that.

Any help would be greatly greatly appreciated

thanks.

Reply | Threaded
Open this post in threaded view
|

Re: Does ibatis support Constructor with arguments?

jaggernat12345
>>> why dont you add a no-argument constructor?

because i cant. If i could add the no arg constructor then there is no problem at all.
Problems like this arises when you extend immutable classes.
 
rd_djunaedi wrote
hi jaggernat12345 ,
im not so sure if ibatis does (or doesnt) support your case, but why dont you add a no-argument constructor?

Is there any reason why you dont do that?
 
hi guys

Is it a MUST that my resultClass have a no -arg constructor ?

I have been struggling whole day resolving this issue. I am using Spring with Ibatis. This is my complete code.


I have in my xml file

------------------------------------------
<typeAlias alias ="userInfo" type ="nj.ado.UserInformation"/>

<select id ="my.query" resultClass="userInfo" parameterclass="java.lang.String">
select A.username,A.Id from User A where A.username= #username:CHAR#
</select>
-------------------------------------------


This is my UserInformation.java

----------------------------------------
public class UserInformation extends org.springframework.security.userdetails.User
{
public String accountId = null;
public UserInformation(String username,String password,boolean enabled,GrantedAuthority[]
  authorities, String accountId) throws IllegalArgumentException
        {
        super(username,password,enabled,authorities); // calls superclass constructor
        this.accountId = accountId;
        }
setAccountId();
getAccountId();
}
-------------------------------------

This is how i am calling the query
----------------------------------------------
UserInformation ui = (UserInformation)SqlMapClientTemplate.queryForObject("my.query" , username);
------------------------------------------------

pretty straightforward.

AND this is the error i get
>>>>
InstantiationException. UserInformation canot be instantiated

I am assuming it is because i dont have a no argument constructor in UserInformation.java ? Is that the problem?

PS: I cannot have a no argument constructor in UserInformation.java because spring doesnt allow me to do that.

Any help would be greatly greatly appreciated

thanks.