• 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
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Would like to confirm if I get the relationship between these entities right

 
Ranch Hand
Posts: 821
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need some help to verify if I get the relationships of these entities correct.  It is using Spring JPA.



I feel that the rest are One to One but really I am not sure cos it's been 4 years already since I touched JPA....

Please help me and let me know if there are anything wrong with the relationships...
Tks.
 
Saloon Keeper
Posts: 13281
292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@OneToMany is used when one instance of your class is associated with many other instances. That means you should apply it to fields of a collection type. You also shouldn't use it on IDs, but rather on the actual type that the ID references.

If you can order multiple pets in one order, then the relationship in Order should be @OneToMany and it should apply to a Set<Pet>, not a single pet ID. The quantity field serves no purpose if you reference each individual pet using a set.

I assume that a pet can only belong to one category. That means that the relationship in Pet is @ManyToOne and applies to a field of type Category.

I don't know what the purpose of Tag is, but if you can apply many different tags to a single pet, and you can also apply the same tag to different pets, then the relationship should be @ManyToMany and apply to a Set<Tag>.

Use an enum to represent enums, not String or Integer. This goes for User.userStatus, Order.status and Pet.status, although I'm not quite sure what the purpose of User.userStatus is.

Why does User reference another User?

I don't think that using a Map in your Pet class is such a good idea. What does the key of the map represent? By the way, use the URL class for URLs, not String.

Why are you storing responses in your database?
 
tangara goh
Ranch Hand
Posts: 821
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:@OneToMany

Why are you storing responses in your database?



Thanks Stephan...I am glad that I am not the only one that feel blurred about this structure but then let me clarify with my supervisor about it.

Actually, this is a REST app with the typical POST, PUT etc where one of it is Updating a pet in the store with a form data.

I guess I need to create another question in the right forum...cos I really don't think I can handle this alone....

May I know why you mentioned storing responses in my database ?

But, this is a REST, should it be stored in a database for consuming..?
 
Stephan van Hulst
Saloon Keeper
Posts: 13281
292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:May I know why you mentioned storing responses in my database ?


Because you gave a class ApiResponse in the description of your entities.

But, this is a REST, should it be stored in a database for consuming..?


I don't really know what you mean by this. If your question is whether you should store API responses in the database, my first instinct is no, you should not. But I don't know the design of the application, so maybe your supervisor can shed more light on this.
 
tangara goh
Ranch Hand
Posts: 821
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:

tangara goh wrote:May I know why you mentioned storing responses in my database ?


Because you gave a class ApiResponse in the description of your entities.

But, this is a REST, should it be stored in a database for consuming..?


I don't really know what you mean by this. If your question is whether you should store API responses in the database, my first instinct is no, you should not. But I don't know the design of the application, so maybe your supervisor can shed more light on this.



Thanks Stephan.  Thank God I still have this forum to ask for opinion ....

I'd check with her cos the API responses she indicated it as part of the Models but then it is not part of the REST response....

 
Stephan van Hulst
Saloon Keeper
Posts: 13281
292
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by the API response is not part of the REST response?
 
tangara goh
Ranch Hand
Posts: 821
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:What do you mean by the API response is not part of the REST response?



It means that there is no end point needed for API response.

Meanwhile I am still waiting for a response on my clarification from my supervisor...
 
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic