@JoinColumn & @JoinTable — Concept Check
Questions on @JoinColumn & @JoinTable. @JoinColumn customises the FK column name on the owning side; @JoinTable specifies the join table name and both FK column names for a @ManyToMany relationship.
Questions in this quiz
8 questions on @JoinColumn & @JoinTable — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.In a @ManyToOne relationship, what is the effect of using @JoinColumn with a specified name?
- AIt specifies the primary key column name on the inverse side.
- BIt customizes the foreign key column name on the owning side.
- CIt changes the table name for the relationship.
- DIt automatically sets FetchType to EAGER.
2.A developer notices that changes to a collection in an entity annotated with @ManyToMany are not persisted. What could be the issue?
- AThe collection is on the inverse side without @JoinTable.
- BThe @JoinColumn is missing on the inverse side.
- CThe collection should use List instead of Set.
- DThe FetchType should be EAGER instead of LAZY.
3.What is a potential consequence of not using FetchType.LAZY in a @ManyToOne relationship?
- ALoss of data integrity constraints.
- BDelayed loading of the parent entity.
- CAutomatic creation of a join table.
- DEager loading of the parent entity on every query.
4.Why should a Set be used instead of a List in a @ManyToMany relationship?
- ATo ensure ordering of elements.
- BTo allow duplicate entries.
- CTo avoid MultipleBagFetchException.
- DTo automatically handle cascading deletes.
5.In a @OneToOne relationship, which side holds the foreign key when using @JoinColumn?
- AThe owning side with @JoinColumn holds the foreign key.
- BNeither side holds a foreign key.
- CThe inverse side holds the foreign key.
- DBoth sides hold a foreign key.
6.A developer wants to ensure a foreign key constraint is named in a @ManyToOne relationship. How can this be achieved?
- ASpecify the constraint in the database directly.
- BUse @ManyToMany with a named table.
- CUse @JoinTable with a named constraint.
- DUse @JoinColumn with foreignKey attribute.
7.What is the purpose of the inverseJoinColumns attribute in a @JoinTable annotation?
- AIt specifies the primary key column of the owning entity.
- BIt specifies the foreign key column pointing to the inverse entity.
- CIt defines the table name for the relationship.
- DIt sets the FetchType for the inverse entity.
8.In a @ManyToMany relationship, what happens if @JoinTable is not used?
- AThe application throws an exception at runtime.
- BHibernate generates a default join table with default column names.
- CThe relationship is not persisted at all.
- DBoth entities become the owning side.