• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with collection

 
Hengki Widjaja
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64959
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keeping the error a secret does not help us help you.
 
Hengki Widjaja
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, sorry. I forgot
the error message was : cannot convert from object to list.
 
Harsha Smith
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
TypeCast it to List. Please paste the entire code to help you better
 
Hengki Widjaja
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator






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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It prints 1,2,3. Please recheck.

 
Hengki Widjaja
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic