package example.springdata.jdbc.howto.idgeneration;

import java.util.UUID;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.relational.core.mapping.event.BeforeSaveCallback;

@SpringBootApplication
class IdGenerationApplication {

	public static void main(String[] args) {
		SpringApplication.run(IdGenerationApplication.class, args);
	}

	@Bean
	BeforeSaveCallback<StringIdMinion> beforeSaveCallback() {

		return (minion, mutableAggregateChange) -> {
			if (minion.id == null) {
				minion.id = UUID.randomUUID().toString();
			}
			return minion;
		};
	}

}

package example.springdata.jdbc.howto.idgeneration;

import java.util.UUID;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.relational.core.mapping.event.BeforeConvertCallback;

@SpringBootApplication
class IdGenerationApplication {

	public static void main(String[] args) {
		SpringApplication.run(IdGenerationApplication.class, args);
	}

	@Bean
	BeforeConvertCallback<StringIdMinion> beforeSaveCallback() {

		return (minion) -> {
			if (minion.id == null) {
				minion.id = UUID.randomUUID().toString();
			}
			return minion;
		};
	}

}

Use BeforeConvertCallback to generate entity identifiers.
Use BeforeConvertCallback to generate entity identifiers.

Related ticket: https://github.com/spring-projects/spring-data-relational/issues/1232
See #636
