У меня есть основной класс:
@SpringBootApplication
@EnableScheduling
@ConfigurationPropertiesScan
@EnableJpaAuditing(auditorAwareRef = "auditorAwareImpl")
public class PlanetsApplication {
public static void main(String[] args) {
SpringApplication.run(PlanetsApplication.class, args);
}
}
и
@Component("auditorAwareImpl")
public class AuditorAwareImpl implements AuditorAware {
@NotNull
@Override
public Optional getCurrentAuditor() {
return Optional.of("system");
}
}
и
@Getter
@Setter
@EntityListeners(AuditingEntityListener.class)
@MappedSuperclass
public class BaseEntity {
@CreatedDate
@Column(updatable = false)
protected LocalDateTime createdAt;
@CreatedBy
@Column(updatable = false)
private String createdBy;
@LastModifiedDate
@Column(updatable = false)
protected LocalDateTime updatedAt;
@LastModifiedBy
@Column(updatable = false)
protected String updatedBy;
}
и
@Entity
@Table(name = "t_spotify_playlist", uniqueConstraints =
@UniqueConstraint(columnNames = {"playlistId", "sun", "moon"}))
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SpotifyPlayList extends BaseEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String playlistId;
@Column(length = 50)
private String sun;
@Column(length = 50)
private String moon;
// Many-to-Many relationship with SpotifyTrack
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "t_playlist_track", // Join table name
joinColumns = @JoinColumn(name = "playlist_id"), // Foreign key for SpotifyPlayListDesc
inverseJoinColumns = @JoinColumn(name = "track_id") // Foreign key for SpotifyTrack
)
private Set tracks; // Tracks associated with the playlist
}
Я сохраняю объект:
SpotifyPlayList spotifyPlayList2 = spotifyPlayListService.findAll().stream().findAny().get();
spotifyPlayList2.setSun(spotifyPlayList2.getSun().toUpperCase());
spotifyPlayListService.save(spotifyPlayList2);
log.info("saved {} ", spotifyPlayList2);
но в БД ничего не проверяется
в журналах:
Hibernate:
update
t_spotify_playlist
set
moon=?,
playlist_id=?,
sun=?
where
id=?
Подробнее здесь: https://stackoverflow.com/questions/793 ... pplication
Как включить и настроить аудит в приложении Spring Boot ⇐ JAVA
Программисты JAVA общаются здесь
-
Anonymous
1737112066
Anonymous
У меня есть основной класс:
@SpringBootApplication
@EnableScheduling
@ConfigurationPropertiesScan
@EnableJpaAuditing(auditorAwareRef = "auditorAwareImpl")
public class PlanetsApplication {
public static void main(String[] args) {
SpringApplication.run(PlanetsApplication.class, args);
}
}
и
@Component("auditorAwareImpl")
public class AuditorAwareImpl implements AuditorAware {
@NotNull
@Override
public Optional getCurrentAuditor() {
return Optional.of("system");
}
}
и
@Getter
@Setter
@EntityListeners(AuditingEntityListener.class)
@MappedSuperclass
public class BaseEntity {
@CreatedDate
@Column(updatable = false)
protected LocalDateTime createdAt;
@CreatedBy
@Column(updatable = false)
private String createdBy;
@LastModifiedDate
@Column(updatable = false)
protected LocalDateTime updatedAt;
@LastModifiedBy
@Column(updatable = false)
protected String updatedBy;
}
и
@Entity
@Table(name = "t_spotify_playlist", uniqueConstraints =
@UniqueConstraint(columnNames = {"playlistId", "sun", "moon"}))
@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class SpotifyPlayList extends BaseEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String playlistId;
@Column(length = 50)
private String sun;
@Column(length = 50)
private String moon;
// Many-to-Many relationship with SpotifyTrack
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "t_playlist_track", // Join table name
joinColumns = @JoinColumn(name = "playlist_id"), // Foreign key for SpotifyPlayListDesc
inverseJoinColumns = @JoinColumn(name = "track_id") // Foreign key for SpotifyTrack
)
private Set tracks; // Tracks associated with the playlist
}
Я сохраняю объект:
SpotifyPlayList spotifyPlayList2 = spotifyPlayListService.findAll().stream().findAny().get();
spotifyPlayList2.setSun(spotifyPlayList2.getSun().toUpperCase());
spotifyPlayListService.save(spotifyPlayList2);
log.info("saved {} ", spotifyPlayList2);
но в БД ничего не проверяется
в журналах:
Hibernate:
update
t_spotify_playlist
set
moon=?,
playlist_id=?,
sun=?
where
id=?
Подробнее здесь: [url]https://stackoverflow.com/questions/79364218/how-to-enable-and-configure-auditing-in-a-spring-boot-application[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия