У меня есть автоинкремент, установленный на мой первичный ключ, но когда я выполняю сохранение в цикле while, он вставляет первые данные с первичным ключом 1, а вторые данные не вставляются как первичный ключ2, а обновляет запись с первичным ключом 1, где первичный равен 1
поэтому я получаю
2017-01-01 00:00:11.763|192.168.234.82|"GET / HTTP/1.1"|200|"swcd (unknown version) CFNetwork/808.2.16 Darwin/15.6.0"
Hibernate: insert into log_bean (date_time, ip_address, request, status, user_agent) values (?, ?, ?, ?, ?)
2017-01-01 00:00:21.164|192.168.234.82|"GET / HTTP/1.1"|200|"swcd (unknown version) CFNetwork/808.2.16 Darwin/15.6.0"
Hibernate: select logbean0_.id as id1_0_0_, logbean0_.date_time as date_tim2_0_0_, logbean0_.ip_address as ip_addre3_0_0_, logbean0_.request as request4_0_0_, logbean0_.status as status5_0_0_, logbean0_.user_agent as user_age6_0_0_ from log_bean logbean0_ where logbean0_.id=?
Hibernate: update log_bean set date_time=?, ip_address=?, request=?, status=?, user_agent=? where id=?
2017-01-01 00:00:23.003|192.168.169.194|"GET / HTTP/1.1"|200|"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"
Hibernate: select logbean0_.id as id1_0_0_, logbean0_.date_time as date_tim2_0_0_, logbean0_.ip_address as ip_addre3_0_0_, logbean0_.request as request4_0_0_, logbean0_.status as status5_0_0_, logbean0_.user_agent as user_age6_0_0_ from log_bean logbean0_ where logbean0_.id=?
Hibernate: update log_bean set date_time=?, ip_address=?, request=?, status=?, user_agent=? where id=?
2017-01-01 00:00:40.554|192.168.234.82|"GET / HTTP/1.1"|200|"swcd (unknown version) CFNetwork/808.2.16 Darwin/15.6.0"
обновлений вместо вставок, вот мой код
public void readFile(LogBean logBean) throws IOException {
Scanner read = new Scanner(
new File(
"/home/user/MyProjects/java-recruitment-task/parserproject/src/main/resources/access.txt"));
while (read.hasNext()) { //checks if there is a valid token
String string = read.nextLine();
System.out.println(string);
Scanner readFileByLine = new Scanner(string);
while (readFileByLine.hasNext()) { //checks valid token if not then goes out of loop
String[] split = readFileByLine.nextLine().split("\\|");
logBean.setDateTime(LocalDateTime.parse(split[0], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")));
logBean.setIp_address(split[1]);
logBean.setRequest(split[2]);
logBean.setStatus(split[3]);
logBean.setUserAgent(split[4]);
}
logbeanRepository.save(logBean);
}
}
, а мой бин
@Entity
public class LogBean {
@Id
@Column(name = "id", updatable = false, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
что я делаю неправильно?это при загрузке весной, поэтому мои свойства базы данных - app.properties