• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Inheritance in Spring

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please see the below code,

I have two classes Person and Student, such a way that Student extends Person.

Person class


Student class


and my configuration file is as follows


and now through my client, I'm expecting to instantiate Student bean through IoC and need to display the id, name and class. But unfortunately, I'm able to display only the class name.




From the output, I observe that the constructor of Person is invoked when IoC instantiates Student as expected. But when I try displaying the ID and Name, they are displayed as null. Doesn't Spring container assign the values for parent object, before setting them to child object.

 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Schandha Ravi wrote:From the output, I observe that the constructor of Person is invoked when IoC instantiates Student as expected. But when I try displaying the ID and Name, they are displayed as null. Doesn't Spring container assign the values for parent object, before setting them to child object.


Spring doesn't know anything unless you tell it. That is those are just two beans spring instantiates. I haven't tried it but check this
 
Schandha Ravi
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Vijitha Kumara.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must fill attribute "parent". So for example parent="Person".

Good Luck !
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic