These are chat archives for hibernate/hibernate-orm

29th
Jun 2017
Chris Cranford
@Naros
Jun 29 2017 13:26
@bigalnz That is probably somewhat of a debatable question depending on whom you ask.
Personally, I prefer avoiding the usage of getter/setters to apply business logic to my domain entities.
When I need something like this, I prefer to mark the setter as protected and expose a specific business function for this use case.
private void setName(String name) { this.name = name; }
private void myFancyMethodThatDoesStuffNamedAppropriately(String name) {
  // do other stuff / business logic here
  setName( name );
}
```
protected void setName(String name) { this.name = name; }
public void myFancyMethodThatDoesStuffNamedAppropriately(String name) {
  // do other stuff / business logic here
  setName( name );
}
Al Grant
@bigalnz
Jun 29 2017 19:36
@Naros in the saveEpisode method I just added this:
// Check if new episode
if (episode.getCreatingUser() == null) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
User user = userRepository.findByEmail(auth.getName());
episode.setCreatingUser(user);
}