• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with StoreController servlet in Spring MVC

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm working through a tutorial on Spring MVC and I am getting an error in my StoreController that I cant seem to sort. The two code snippets I have added are StoreController.java and Genre.java which is an Entity class. I am getting an error @ line 76 of StoreController as follows: The method getName() is undefined for type Integer. I will add the code just below and I hope someone can help me understand my problem:
Thanks and regards
Gus



StoreController.java

 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Since code of class Album is not posted, I can only guess that probably Album.getGenreid() is returning an Integer instead of a Genre.
 
Gus Hayes
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Album class is not being modelled the right way. Make it related to Genre and Artist entities directly by having them as members, instead of their IDs.
The ID management is supposed to be handled transparently by the ORM.

Then album.getGenre().getName().equals(genreName) makes sense because getGenre() is returning an actual Genre object, instead of its Integer ID.
 
Gus Hayes
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your helpful replies,
Do you mean that I need to add imports statements for each entity class and model class I refer to in the StoreController class.
Apologies for my newbie fumblings
Regards
Gus
 
Gus Hayes
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Karthik
Could you please explain what you mean by not modelling it the right way. I dont understand as I am new to this.
Thanks,
Gus
 
Karthik Shiraly
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I meant model the relationships between Album and Genre, and Album and Artist, in a natural way. The Album should have Genre and Artist as members, not their IDs.
Currently, you have their IDs as members and so Album.getGenre() returns an Integer object. How can an Integer object have a getName() method?

 
Gus Hayes
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Karthik,
I have followed the tutorial line for line and it worked on the tutors side but when I entered the code as per tutorial I got the getName() problem. I dont understand what you mean by making them as members of the Album class and not their ID's as members. Apologies for my lack of understanding.
Regards,
Gus
 
I knew I would regret that burrito. But this tiny ad has never caused regrets:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic