Card 06/ 07

ExerciseDifficulty: Advanced1 min

Name the State

Trace this sequence and say what state t is in after each line:

java
Ticket t = new Ticket("open");        // (a)
em.persist(t);                        // (b)
em.detach(t);                         // (c)
t.status = "escalated";               // (d)
See the answers

(a) Transient — just constructed, nothing knows about it. (b) Managed — the persistence context is now tracking it. (c) Detached — tracking stopped; the row (if one exists yet) is untouched by anything from here on. (d) Still detached — the field genuinely changes in memory, but nothing is watching, so nothing about this line reaches the database.