liveBook · Manning

Data integrity

As explained in Java Persistence with Spring Data and Hibernate epub

Data integrity is the preservation of correctness and consistency of data and its enforced relationships.

Data integrity preserves correctness and consistency across object relationships and relational schemas. In a bidirectional Item–Bid association, both object references must agree; in an inheritance mapping, table design affects constraints, normalization, and schema evolution. section 3.2.4 section 7.9

Maintain association integrity explicitly:

  • Add the Bid to the Item’s collection and set the Bid’s item property. section 3.2.4
  • Use a convenience method or constructor to perform both updates and reject null or already-assigned bids. section 3.2.4
  • Store bid amount and creation time rather than display order; sort when querying or presenting data. section 3.2.4

Keeping both sides consistent

public void addBid(Bid bid) { if (bid == null) throw new NullPointerException("Can't add null Bid"); if (bid.getItem() != null) throw new IllegalStateException("Bid is already assigned to an Item"); bids.add(bid); bid.setItem(this); } section 3.2.4

Inheritance mapping introduces a different integrity tradeoff. A single table simplifies queries and performs well but requires nullable columns and can violate third normal form. Joined subclass tables normalize the schema and simplify integrity constraints, at the cost of more complex implementation and potentially slower queries. section 7.9

Figure 3.4 Associations between the Item and Bid classes

Inspect the Item–Bid association diagram to see the two references that must remain synchronized. section 3.2.4

How Java Persistence with Spring Data and Hibernate epub covers it

How deep it goes
Explains two-sided association updates with validation and compares inheritance schemas, stopping short of provider-specific implementation details.
Examples
Uses Item–Bid Java classes, a bid-linking helper, auction bid amounts and timestamps, and competing inheritance table strategies.
What it assumes
Assumes Java object associations, JPA persistence concepts, and relational schema terminology.
What you can do after
Apply association helpers and mapping choices that keep object references, constraints, and stored data consistent.
How it connects
Connects bidirectional associations, foreign key constraints, inheritance mapping, normalization, schema evolution, and polymorphism.

Also explained in

Compare how 18 books explain data integrity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Java Persistence with Spring Data and Hibernate epub. The section links point to the parts of the book it draws on.