| Author |
problem with collection
|
Hengki Widjaja
Ranch Hand
Joined: Oct 31, 2011
Posts: 44
|
|
I have a class with content like this:
when I use field.get on purchaseCode or purchaseDate, no problem. but when I try to access the purchaseDetail(s), this technique gives me an error. help please? thanks
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56529
|
|
|
Keeping the error a secret does not help us help you.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Hengki Widjaja
Ranch Hand
Joined: Oct 31, 2011
Posts: 44
|
|
Oh, sorry. I forgot
the error message was : cannot convert from object to list.
|
 |
Harsha Smith
Ranch Hand
Joined: Jul 18, 2011
Posts: 287
|
|
|
TypeCast it to List. Please paste the entire code to help you better
|
 |
Hengki Widjaja
Ranch Hand
Joined: Oct 31, 2011
Posts: 44
|
|
Ah yes, forgot the typecast. it should return 1, 2 and 3. instead, it returned 0,0,3. am I missing something?
|
 |
Hengki Widjaja
Ranch Hand
Joined: Oct 31, 2011
Posts: 44
|
|
ahh, silly mistake. I forgot to change the value from the input file. but I have another question. I had to do this:
to get the value. is there a more generic way, so I don't need to change this for every different type? thanks
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16487
|
|
|
No, that's the sort of thing you have to do when you use reflection. But why are you using reflection anyway?
|
 |
Harsha Smith
Ranch Hand
Joined: Jul 18, 2011
Posts: 287
|
|
It prints 1,2,3. Please recheck.
|
 |
Hengki Widjaja
Ranch Hand
Joined: Oct 31, 2011
Posts: 44
|
|
@Harsha:
yes, it was some silly mistake. it prints correctly now.
@Paul:
I use reflection to create some sort of simple class parser. So, I got assignment to make a basic ORM project. the class is used to take an object as a parameter and then translate that into a SQL insert string. in order to do this, I need to get the members of the object. now I'm struggling with the cascade insertion (i.e. the member of class that's a collection). any idea? thanks
|
 |
Hengki Widjaja
Ranch Hand
Joined: Oct 31, 2011
Posts: 44
|
|
Thanks for the help, guys. apparently the silly cast is all I need. what a blunder. thanks again. have a nice day!!
As for the cascade, actually it's just a thought. it's not required. so I'll just leave it at that. besides, I don't have any plan of competing with hibernate.
|
 |
 |
|
|
subject: problem with collection
|
|
|