Я создал новую таблицу, которая переносится через FlywayDB при запуске:
CREATE TABLE IF NOT EXISTS place_address (
id bigint,
place_id bigint NOT NULL,
street character varying(255) NOT NULL,
postal_code character varying(255) NOT NULL,
city character varying(255) NOT NULL,
country character varying(255) NOT NULL,
address_type character varying(255) NOT NULL,
FOREIGN KEY (place_id) REFERENCES place(id),
CONSTRAINT place_address_pkey PRIMARY KEY (id)
);
Я создаю такую сущность и сохраняю ее с JpaRepository
:
PlaceAddressEntity placeAddressEntity = new PlaceAddressEntity();
placeAddressEntity.setPlace(placeEntity);
placeAddressEntity.setStreet(establishmentDto.getAddress().getStreet());
placeAddressEntity.setCity(establishmentDto.getAddress().getCity());
placeAddressEntity.setCountry(establishmentDto.getAddress().getCountry());
placeAddressEntity.setPostalCode(establishmentDto.getAddress().getPostalCode());
placeAddressEntity.setAddressType(AddressType.GEOGRAPHIC);
this.placeAddessRepository.save(placeAddressEntity);
Однаковот что я получаю:
2018-09-21 18:42:05.319 WARN 13842 --- [io-8443-exec-10] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: 23502
2018-09-21 18:42:05.319 ERROR 13842 --- [io-8443-exec-10] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: null value in column "id" violates not-null constraint
Detail: Failing row contains (null, 8, Western Road 2-20, NW10 7LW, Greater London, United Kingdom, GEOGRAPHIC).
2018-09-21 18:42:05.322 INFO 13842 --- [io-8443-exec-10] m.a.s.e.CustomRestExceptionHandler : org.springframework.dao.DataIntegrityViolationException
2018-09-21 18:42:05.323 INFO 13842 --- [io-8443-exec-10] m.a.s.e.CustomRestExceptionHandler : org.hibernate.exception.ConstraintViolationException
Сущность определяется как:
@Entity
@Table(name = "place_address")
public class PlaceAddressEntity {
public enum AddressType {
GEOGRAPHIC,
BILLING
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
@JoinColumn(name = "place_id", nullable = false)
private PlaceEntity place;
@Column
private String street;
@Column(name = "postal_code")
private String postalCode;
@Column
private String city;
@Column
private String country;
@Column(name = "address_type")
@Enumerated(EnumType.STRING)
private AddressType addressType;
}
Я понятия не имею, в чем проблема - есть идеи, что мне не хватает?
Здесь также PlaceAddressRepository
:
public interface PlaceAddessRepository extends JpaRepository<PlaceAddressEntity, Long> {
}