Skip to content

Instantly share code, notes, and snippets.

@thjanssen
Created November 22, 2016 17:33
Show Gist options
  • Save thjanssen/66ecc4094ed65bf464724e0103cf173c to your computer and use it in GitHub Desktop.
Save thjanssen/66ecc4094ed65bf464724e0103cf173c to your computer and use it in GitHub Desktop.
@Entity
@NamedQuery(name = “Account.FindByName”, query = “SELECT a FROM Account a WHERE name like :name”)
public class Account {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = “id”, updatable = false, nullable = false)
private Long id;
@Column
private String name;
@Column
@Enumerated(EnumType.STRING)
private AccountState state;
}
Account a = em.find(Account.class, a.getId());
em.remove(a);
16:07:59,511 DEBUG SQL:92 – select account0_.id as id1_0_0_, account0_.name as name2_0_0_, account0_.state as state3_0_0_ from Account account0_ where account0_.id=? and ( account0_.state <> ‘DELETED’)
16:07:59,534 DEBUG SQL:92 – UPDATE account SET state = ‘DELETED’ WHERE id = ?
Account a = em.find(Account.class, a.getId());
16:07:59,540 DEBUG SQL:92 – select account0_.id as id1_0_0_, account0_.name as name2_0_0_, account0_.state as state3_0_0_ from Account account0_ where account0_.id=? and ( account0_.state <> ‘DELETED’)
TypedQuery<Account> q = em.createNamedQuery(“Account.FindByName”, Account.class);
q.setParameter(“name”, “%ans%”);
Account a = q.getSingleResult();
16:07:59,511 DEBUG SQL:92 – select account0_.id as id1_0_, account0_.name as name2_0_, account0_.state as state3_0_ from Account account0_ where ( account0_.state <> ‘DELETED’) and (account0_.name like ?)
@Entity
@SQLDelete(sql = “UPDATE account SET state = ‘DELETED’ WHERE id = ?”, check = ResultCheckStyle.COUNT)
public class Account {
@PreRemove
public void deleteUser() {
this.state = AccountState.DELETED;
}
}
@Entity
@SQLDelete(sql = “UPDATE account SET state = ‘DELETED’ WHERE id = ?”, check = ResultCheckStyle.COUNT)
public class Account { … }
@Entity
@SQLDelete(sql = “UPDATE account SET state = ‘DELETED’ WHERE id = ?”, check = ResultCheckStyle.COUNT)
@Where(clause = “state <> ‘DELETED'”)
@NamedQuery(name = “Account.FindByName”, query = “SELECT a FROM Account a WHERE name like :name”)
public class Account { … }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment