• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

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

 
Ranch Hand
Posts: 1748
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: 3292
296
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree!
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!