You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by slideharmony <se...@tiscali.it> on 2007/11/16 15:35:26 UTC

ClassCastException

Hello,
I have a problem saving a bean User. I use the following code:

UserDao dao = new UserDao();
User user = new User();
Service.populate(user);
dao.save(utente);
if(user != null){
return SUCCESS;
}

here is the dao.save method:


public User save(User user){
Utente newuser = null;
begin();
newuser = (User)getSession().save(user);
commit();
close();
return newuser;
}

this code throws a ClassCastException: java.lang.Long
I have mapped all correctly, i have the same code that works perfectly in
struts, but I get that exception with struts2. Can anybody help me?
-- 
View this message in context: http://www.nabble.com/ClassCastException-tf4821639.html#a13794339
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: ClassCastException

Posted by slideharmony <se...@tiscali.it>.
yes, it was the problem, I have solved it! thanks



Nils-Helge Garli wrote:
> 
> Assuming you're using Hibernate or something, the save method probably
> returns the generated identity of the stored object instance. So my
> guess is that you're getting the id of the user returned, which is a
> Long, and not a User object.
> 
> Nils-H
> 
> On 11/16/07, slideharmony <se...@tiscali.it> wrote:
>>
>> this line:
>> newuser = (User)getSession().save(user);
>>
>>
>>
>> Hernandez, David wrote:
>> >
>> >
>> > What line's the Exception being thrown on?
>> >
>> > -----Original Message-----
>> > From: slideharmony [mailto:setoiori@tiscali.it]
>> > Sent: Friday, November 16, 2007 9:35 AM
>> > To: user@struts.apache.org
>> > Subject: ClassCastException
>> >
>> >
>> > Hello,
>> > I have a problem saving a bean User. I use the following code:
>> >
>> > UserDao dao = new UserDao();
>> > User user = new User();
>> > Service.populate(user);
>> > dao.save(utente);
>> > if(user != null){
>> > return SUCCESS;
>> > }
>> >
>> > here is the dao.save method:
>> >
>> >
>> > public User save(User user){
>> > Utente newuser = null;
>> > begin();
>> > newuser = (User)getSession().save(user); commit(); close(); return
>> > newuser; }
>> >
>> > this code throws a ClassCastException: java.lang.Long I have mapped all
>> > correctly, i have the same code that works perfectly in struts, but I
>> > get that exception with struts2. Can anybody help me?
>> > --
>> > View this message in context:
>> > http://www.nabble.com/ClassCastException-tf4821639.html#a13794339
>> > Sent from the Struts - User mailing list archive at Nabble.com.
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> > For additional commands, e-mail: user-help@struts.apache.org
>> >
>> > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>> -
>> > - - - - - - -
>> >
>> > This message is intended only for the personal and confidential use of
>> the
>> > designated recipient(s) named above.  If you are not the intended
>> > recipient of this message you are hereby notified that any review,
>> > dissemination, distribution or copying of this message is strictly
>> > prohibited.  This communication is for information purposes only and
>> > should not be regarded as an offer to sell or as a solicitation of an
>> > offer to buy any financial product, an official confirmation of any
>> > transaction, or as an official statement of Lehman Brothers.  Email
>> > transmission cannot be guaranteed to be secure or error-free. 
>> Therefore,
>> > we do not represent that this information is complete or accurate and
>> it
>> > should not be relied upon as such.  All information is subject to
>> change
>> > without notice.
>> >
>> > --------
>> > IRS Circular 230 Disclosure:
>> > Please be advised that any discussion of U.S. tax matters contained
>> within
>> > this communication (including any attachments) is not intended or
>> written
>> > to be used and cannot be used for the purpose of (i) avoiding U.S. tax
>> > related penalties or (ii) promoting, marketing or recommending to
>> another
>> > party any transaction or matter addressed herein.
>> >
>> >
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> > For additional commands, e-mail: user-help@struts.apache.org
>> >
>> >
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/ClassCastException-tf4821639.html#a13794434
>> Sent from the Struts - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/ClassCastException-tf4821639.html#a13795487
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: ClassCastException

Posted by Nils-Helge Garli Hegvik <ni...@gmail.com>.
Assuming you're using Hibernate or something, the save method probably
returns the generated identity of the stored object instance. So my
guess is that you're getting the id of the user returned, which is a
Long, and not a User object.

Nils-H

On 11/16/07, slideharmony <se...@tiscali.it> wrote:
>
> this line:
> newuser = (User)getSession().save(user);
>
>
>
> Hernandez, David wrote:
> >
> >
> > What line's the Exception being thrown on?
> >
> > -----Original Message-----
> > From: slideharmony [mailto:setoiori@tiscali.it]
> > Sent: Friday, November 16, 2007 9:35 AM
> > To: user@struts.apache.org
> > Subject: ClassCastException
> >
> >
> > Hello,
> > I have a problem saving a bean User. I use the following code:
> >
> > UserDao dao = new UserDao();
> > User user = new User();
> > Service.populate(user);
> > dao.save(utente);
> > if(user != null){
> > return SUCCESS;
> > }
> >
> > here is the dao.save method:
> >
> >
> > public User save(User user){
> > Utente newuser = null;
> > begin();
> > newuser = (User)getSession().save(user); commit(); close(); return
> > newuser; }
> >
> > this code throws a ClassCastException: java.lang.Long I have mapped all
> > correctly, i have the same code that works perfectly in struts, but I
> > get that exception with struts2. Can anybody help me?
> > --
> > View this message in context:
> > http://www.nabble.com/ClassCastException-tf4821639.html#a13794339
> > Sent from the Struts - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> > - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> > - - - - - - -
> >
> > This message is intended only for the personal and confidential use of the
> > designated recipient(s) named above.  If you are not the intended
> > recipient of this message you are hereby notified that any review,
> > dissemination, distribution or copying of this message is strictly
> > prohibited.  This communication is for information purposes only and
> > should not be regarded as an offer to sell or as a solicitation of an
> > offer to buy any financial product, an official confirmation of any
> > transaction, or as an official statement of Lehman Brothers.  Email
> > transmission cannot be guaranteed to be secure or error-free.  Therefore,
> > we do not represent that this information is complete or accurate and it
> > should not be relied upon as such.  All information is subject to change
> > without notice.
> >
> > --------
> > IRS Circular 230 Disclosure:
> > Please be advised that any discussion of U.S. tax matters contained within
> > this communication (including any attachments) is not intended or written
> > to be used and cannot be used for the purpose of (i) avoiding U.S. tax
> > related penalties or (ii) promoting, marketing or recommending to another
> > party any transaction or matter addressed herein.
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> >
>
> --
> View this message in context: http://www.nabble.com/ClassCastException-tf4821639.html#a13794434
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

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


RE: ClassCastException

Posted by slideharmony <se...@tiscali.it>.
this line:
newuser = (User)getSession().save(user);



Hernandez, David wrote:
> 
> 
> What line's the Exception being thrown on? 
> 
> -----Original Message-----
> From: slideharmony [mailto:setoiori@tiscali.it] 
> Sent: Friday, November 16, 2007 9:35 AM
> To: user@struts.apache.org
> Subject: ClassCastException
> 
> 
> Hello,
> I have a problem saving a bean User. I use the following code:
> 
> UserDao dao = new UserDao();
> User user = new User();
> Service.populate(user);
> dao.save(utente);
> if(user != null){
> return SUCCESS;
> }
> 
> here is the dao.save method:
> 
> 
> public User save(User user){
> Utente newuser = null;
> begin();
> newuser = (User)getSession().save(user); commit(); close(); return
> newuser; }
> 
> this code throws a ClassCastException: java.lang.Long I have mapped all
> correctly, i have the same code that works perfectly in struts, but I
> get that exception with struts2. Can anybody help me?
> --
> View this message in context:
> http://www.nabble.com/ClassCastException-tf4821639.html#a13794339
> Sent from the Struts - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> - - - - - - -
> 
> This message is intended only for the personal and confidential use of the
> designated recipient(s) named above.  If you are not the intended
> recipient of this message you are hereby notified that any review,
> dissemination, distribution or copying of this message is strictly
> prohibited.  This communication is for information purposes only and
> should not be regarded as an offer to sell or as a solicitation of an
> offer to buy any financial product, an official confirmation of any
> transaction, or as an official statement of Lehman Brothers.  Email
> transmission cannot be guaranteed to be secure or error-free.  Therefore,
> we do not represent that this information is complete or accurate and it
> should not be relied upon as such.  All information is subject to change
> without notice.
> 
> --------
> IRS Circular 230 Disclosure:
> Please be advised that any discussion of U.S. tax matters contained within
> this communication (including any attachments) is not intended or written
> to be used and cannot be used for the purpose of (i) avoiding U.S. tax
> related penalties or (ii) promoting, marketing or recommending to another
> party any transaction or matter addressed herein.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/ClassCastException-tf4821639.html#a13794434
Sent from the Struts - User mailing list archive at Nabble.com.


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


RE: ClassCastException

Posted by "Hernandez, David" <da...@lehman.com>.
What line's the Exception being thrown on? 

-----Original Message-----
From: slideharmony [mailto:setoiori@tiscali.it] 
Sent: Friday, November 16, 2007 9:35 AM
To: user@struts.apache.org
Subject: ClassCastException


Hello,
I have a problem saving a bean User. I use the following code:

UserDao dao = new UserDao();
User user = new User();
Service.populate(user);
dao.save(utente);
if(user != null){
return SUCCESS;
}

here is the dao.save method:


public User save(User user){
Utente newuser = null;
begin();
newuser = (User)getSession().save(user); commit(); close(); return
newuser; }

this code throws a ClassCastException: java.lang.Long I have mapped all
correctly, i have the same code that works perfectly in struts, but I
get that exception with struts2. Can anybody help me?
--
View this message in context:
http://www.nabble.com/ClassCastException-tf4821639.html#a13794339
Sent from the Struts - User mailing list archive at Nabble.com.


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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

This message is intended only for the personal and confidential use of the designated recipient(s) named above.  If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited.  This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers.  Email transmission cannot be guaranteed to be secure or error-free.  Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such.  All information is subject to change without notice.

--------
IRS Circular 230 Disclosure:
Please be advised that any discussion of U.S. tax matters contained within this communication (including any attachments) is not intended or written to be used and cannot be used for the purpose of (i) avoiding U.S. tax related penalties or (ii) promoting, marketing or recommending to another party any transaction or matter addressed herein.



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


[OT] Re: ClassCastException

Posted by Dave Newton <ne...@yahoo.com>.
What's "utente"?

In any case, you don't say where the exception is, but
for whatever reason your DAO isn't getting a user (if
that's where the exception is).

d.

--- slideharmony <se...@tiscali.it> wrote:

> 
> Hello,
> I have a problem saving a bean User. I use the
> following code:
> 
> UserDao dao = new UserDao();
> User user = new User();
> Service.populate(user);
> dao.save(utente);
> if(user != null){
> return SUCCESS;
> }
> 
> here is the dao.save method:
> 
> 
> public User save(User user){
> Utente newuser = null;
> begin();
> newuser = (User)getSession().save(user);
> commit();
> close();
> return newuser;
> }
> 
> this code throws a ClassCastException:
> java.lang.Long
> I have mapped all correctly, i have the same code
> that works perfectly in
> struts, but I get that exception with struts2. Can
> anybody help me?
> -- 
> View this message in context:
>
http://www.nabble.com/ClassCastException-tf4821639.html#a13794339
> Sent from the Struts - User mailing list archive at
> Nabble.com.
> 
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> user-unsubscribe@struts.apache.org
> For additional commands, e-mail:
> user-help@struts.apache.org
> 
> 


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