Database and Persistence MCQs

  1. Which of the following is true about JDBC?
    a) Java API for database connectivity
    b) Provides DriverManager, Connection, Statement classes
    c) Supports SQL execution
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  2. What will be printed?
    1 import java.sql.*;
    2 public class EduinqJDBC {
    3 public static void main(String[] args) throws Exception {
    4 Connection con = DriverManager.getConnection("jdbc:h2:mem:test","sa","");
    5 Statement st = con.createStatement();
    6 st.execute("CREATE TABLE eduinq(id INT, name VARCHAR)");
    7 st.execute("INSERT INTO eduinq VALUES(1,'Portal')");
    8 ResultSet rs = st.executeQuery("SELECT name FROM eduinq");
    9 while(rs.next()) System.out.println(rs.getString(1));
    10 }
    11 }
    a) Portal
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Portal

  3. Which of the following is true about Hibernate ORM?
    a) Maps Java objects to database tables
    b) Provides HQL for queries
    c) Supports caching and transactions
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  4. Which of the following is true about JPA?
    a) Java Persistence API
    b) Standard for ORM in Java
    c) Uses annotations like @Entity, @Id
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  5. What will be printed?
    1 import javax.persistence.*;
    2 @Entity
    3 class Eduinq {
    4 @Id int id;
    5 String name;
    6 }
    7 public class Test {
    8 public static void main(String[] args) {
    9 System.out.println("Eduinq JPA Entity Ready");
    10 }
    11 }
    a) Eduinq JPA Entity Ready
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq JPA Entity Ready

  6. Which of the following is true about Transactions?
    a) Ensure ACID properties
    b) Managed via JDBC, JPA, Hibernate
    c) Support commit and rollback
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  7. Which of the following is true about Lazy Loading in Hibernate?
    a) Loads data only when accessed
    b) Improves performance
    c) May cause LazyInitializationException if session closed
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  8. Which of the following is true about Eager Loading in Hibernate?
    a) Loads data immediately
    b) May cause unnecessary overhead
    c) Configured via fetch type
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  9. Which of the following is true about Hibernate caching levels?
    a) First level cache is session scoped
    b) Second level cache is session factory scoped
    c) Query cache stores query results
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  10. What will be printed?
    1 System.out.println("Eduinq Hibernate Cache Enabled");
    a) Eduinq Hibernate Cache Enabled
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq Hibernate Cache Enabled

  11. Which of the following is true about JDBC PreparedStatement?
    a) Prevents SQL injection
    b) Allows parameterized queries
    c) Improves performance with caching
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  12. Which of the following is true about JPA EntityManager?
    a) Manages persistence operations
    b) Provides methods like persist(), merge(), remove()
    c) Supports transactions
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  13. Which of the following is true about Hibernate Session?
    a) Provides CRUD operations
    b) Acts as first level cache
    c) Supports transactions
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  14. Which of the following is true about JPA Query Language (JPQL)?
    a) Object oriented query language
    b) Similar to SQL but works with entities
    c) Supports joins, group by, order by
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  15. Which of the following is true about JDBC ResultSet?
    a) Represents query results
    b) Provides methods like next(), getString(), getInt()
    c) Can be scrollable or updatable
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  16. Which of the following is true about Hibernate annotations?
    a) @Entity marks class as persistent
    b) @Table defines table name
    c) @Column defines column mapping
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  17. Which of the following is true about JPA relationships?
    a) @OneToOne, @OneToMany, @ManyToOne, @ManyToMany
    b) Define associations between entities
    c) Support cascade operations
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  18. Which of the following is true about Hibernate Criteria API?
    a) Provides programmatic query construction
    b) Type safe queries
    c) Supports restrictions and projections
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  19. Which of the following is true about JDBC batch processing?
    a) Executes multiple statements together
    b) Improves performance
    c) Uses addBatch() and executeBatch()
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  20. Which of the following is true about JPA NamedQuery?
    a) Predefined queries with @NamedQuery annotation
    b) Improve reusability
    c) Defined at entity level
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  21. Which of the following is true about JDBC Savepoints?
    a) Allow partial rollbacks
    b) Created via Connection.setSavepoint()
    c) Released via Connection.releaseSavepoint()
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  22. Which of the following is true about Hibernate caching strategies?
    a) Read only cache for immutable entities
    b) Read write cache for updatable entities
    c) Non strict read write cache for less strict consistency
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  23. Which of the following is true about JPA inheritance mapping?
    a) @Inheritance(strategy=) defines inheritance type
    b) Strategies include SINGLE_TABLE, JOINED, TABLE_PER_CLASS
    c) Promotes reuse of entity hierarchy
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  24. What will be printed?
    1 import javax.persistence.*;
    2 @Entity
    3 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
    4 class EduinqBase { @Id int id; }
    5 @Entity
    6 class EduinqChild extends EduinqBase { String name; }
    7 public class Test {
    8 public static void main(String[] args) {
    9 System.out.println("Eduinq JPA Inheritance Ready");
    10 }
    11 }
    a) Eduinq JPA Inheritance Ready
    b) Eduinq
    c) Compilation error
    d) Runtime exception
    View Answer

    Correct answer: A — Eduinq JPA Inheritance Ready

  25. Which of the following is true about JPA entity lifecycle states?
    a) New (transient)
    b) Managed (persistent)
    c) Detached
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  26. Which of the following is true about Hibernate dirty checking?
    a) Automatically detects changes in persistent objects
    b) Updates database on transaction commit
    c) Reduces manual update calls
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  27. Which of the following is true about Optimistic Locking?
    a) Uses version field
    b) Prevents lost updates
    c) Throws OptimisticLockException on conflict
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  28. Which of the following is true about Pessimistic Locking?
    a) Locks rows in database
    b) Prevents concurrent modifications
    c) May reduce concurrency
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  29. Which of the following is true about JPA @Version annotation?
    a) Marks field for optimistic locking
    b) Automatically updated on changes
    c) Prevents concurrent update issues
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  30. Which of the following is true about JDBC transaction management?
    a) Auto commit enabled by default
    b) Can disable auto commit for manual control
    c) Supports commit and rollback
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  31. Which of the following is true about Hibernate SessionFactory?
    a) Creates Session objects
    b) Heavyweight, should be created once
    c) Provides second level cache
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  32. Which of the following is true about JPA Entity lifecycle callbacks?
    a) @PrePersist, @PostPersist
    b) @PreUpdate, @PostUpdate
    c) @PreRemove, @PostRemove
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  33. Which of the following is true about JDBC Connection pooling?
    a) Reuses connections
    b) Improves performance
    c) Implemented via libraries like HikariCP, C3P0
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  34. Which of the following is true about Hibernate @Cache annotation?
    a) Configures caching strategy
    b) Works with second level cache providers
    c) Improves performance
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  35. Which of the following is true about JPA Cascade types?
    a) CascadeType.PERSIST
    b) CascadeType.MERGE
    c) CascadeType.REMOVE, REFRESH, DETACH
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  36. Which of the following is true about JDBC CallableStatement?
    a) Executes stored procedures
    b) Supports IN, OUT parameters
    c) Useful for complex logic in DB
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  37. Which of the following is true about Hibernate @NamedQuery?
    a) Defines static queries
    b) Improves reusability
    c) Declared at entity level
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  38. Which of the following is true about JPA Entity states transitions?
    a) persist() moves transient persistent
    b) detach() moves persistent detached
    c) remove() moves persistent removed
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  39. Which of the following is true about JDBC Scrollable ResultSet?
    a) Allows moving cursor forward/backward
    b) Supports absolute positioning
    c) Useful for navigation
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  40. Which of the following is true about Hibernate @Fetch annotation?
    a) Defines fetch strategy
    b) Options include FetchMode.JOIN, SELECT, SUBSELECT
    c) Controls how associations are loaded
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  41. Which of the following is true about JPA @Embedded annotation?
    a) Embeds value type objects
    b) Used for composite attributes
    c) Promotes reuse
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  42. Which of the following is true about JDBC transaction isolation levels?
    a) READ_UNCOMMITTED
    b) READ_COMMITTED
    c) REPEATABLE_READ, SERIALIZABLE
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  43. Which of the following is true about Hibernate @NaturalId?
    a) Marks natural identifier field
    b) Provides efficient lookups
    c) Supports caching
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  44. Which of the following is true about JPA @MappedSuperclass?
    a) Defines base class for entities
    b) Not mapped to table directly
    c) Provides reusable mappings
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  45. Which of the following is true about JDBC Metadata?
    a) DatabaseMetaData provides DB info
    b) ResultSetMetaData provides column info
    c) Useful for dynamic queries
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  46. Which of the following is true about Hibernate @DynamicUpdate?
    a) Updates only modified columns
    b) Improves performance
    c) Reduces unnecessary SQL
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  47. Which of the following is true about JPA Lock modes?
    a) OPTIMISTIC
    b) OPTIMISTIC_FORCE_INCREMENT
    c) PESSIMISTIC_READ, PESSIMISTIC_WRITE
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  48. Which of the following is true about JDBC batch updates best practices?
    a) Use PreparedStatement for efficiency
    b) Commit in chunks
    c) Handle exceptions carefully
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  49. Which of the following is true about Hibernate best practices?
    a) Use lazy loading wisely
    b) Optimize queries with fetch joins
    c) Enable second level cache carefully
    d) All of the above
    View Answer

    Correct answer: D — All of the above

  50. Which of the following is true about JPA best practices?
    a) Use proper cascade types
    b) Avoid eager loading unless necessary
    c) Use DTOs for projections
    d) All of the above
    View Answer

    Correct answer: D — All of the above

Quick Links to Explore