Skip to content

Instantly share code, notes, and snippets.

kubawieczorek

Block or report user

Report or block kubawieczorek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View PlainTransaction.java
Transaction tx = null;
try {
tx = session.beginTransaction();
// do some work
tx.commit();
}
catch (RuntimeException e) {
if (tx != null) tx.rollback();
View RetrieveSession.java
Session session = entityManager.unwrap(Session.class);
View hibernate.xml
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.6.Final</version>
</dependency>
View SessionSave.java
Client client = new Client();
client.setName("newName");
client.setEmail("mail@test.com");
session.save(client);
View Client.java
@Entity
@Table(name = "client")
public class Client {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer clientId;
@Column(name = "name", nullable = false)
private String name;
View sessionUpdate.java
client.setName("newName");
session.update(client);
View sessionFind.java
Client client = session.find(Client.class, 1);
View registerNewAccount.java
@Transactional
public Account registerNewAccount(Client client){
Account account = new Account();
account.setMoney(0);
account.setNumber(randomUUID().toString());
account.setDateCreated(Instant.now());
account.setClient(client);
return accountRepository.save(account);
}
View saveNewClient.java
@Transactional
public Client saveNewClient(ClientDto clientDto) {
Client client = new Client();
client.setName(clientDto.getName());
client.setEmail(clientDto.getEmail());
Client newClient = clientRepository.save(client);
accountService.registerNewAccount(newClient);
return newClient;
}
You can’t perform that action at this time.