Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

My exam cloud mock 3, @OneToMany and @ManyToOne relationships.  RSS feed

 
Ranch Hand
Posts: 1733
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Consider the following relationship in an auction application.
1 category may have 0 or more sub categories.
Select correct code snippet to define this relationshiop.
A. @Entity
   public class Category implements Serializable{
    @OneToMany
    private Category parent;

    @ManyToOne(mappedBy="parent")
     private Collection<Category> children;
    ...
   }

B. @Entity
  public class Category implements Serializable{
   @ManyToOne
    private Category parent;
   @OneToMany(mappedBy="parent")
   private Collection <Category> children;
     ...
   }

c. JPA does not support this kind of relationships.

Given answer is C.
Explanation:
In this relationship each record in Category may have many related records in same table.
We can define this relationship like the following code sample.
@Entity
public class Category implements Serializable{
 @ManyToOne
  private Category parent;
@OneToMany(mappedBy="parent")
 private Collection <Category> children;
}



I think the answer should be B as described in the explanation.
 
Creator of Enthuware JWS+ V6
Posts: 3273
296
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree!
 
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!