gpt4 book ai didi

spring - Spring Boot Batch 中的 Hibernate_sequence 错误(预定)

转载 作者:行者123 更新时间:2023-11-29 13:22:50 30 4
gpt4 key购买 nike

我有一个有趣的情况。我解析了几个新闻发布网站,想通过调度程序将它们保存到数据库中。但是保存时出现错误。由于交易后写条件 described here .

我的模型类是

@Entity
@Table(name="News")
public class News {

@Id
@GeneratedValue(strategy = javax.persistence.GenerationType.TABLE)
private Long id;

@Column(name="title")
private String title;

@Column(name="entity")
private String entity;

@Column(name="text")
private String newsText;

@Column(name="url")
private String url;

@Column(name="newsDate")
private Date newsDate;
//getters and setters}

我的 hibernate 设置(Spring boot 的)

    spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none
create-drop
spring.database.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/projectAn
spring.datasource.username=postgres
spring.datasource.password=Iskandar123

我的spring Batch调度方法

   @Scheduled(initialDelay=5000,fixedRate=5000)
private void mferNews()
{
Document doc;
try
{
doc = Jsoup.connect("http://www.mfer.uz/ru/news/news-uzb/").get();

Elements links = doc.select("a[href^=/ru/news/news-uzb/");

for(Element link : links) {
//System.out.println("");
if(isMatch(link.attr("href")))
{
News news = new News();
//System.out.println("http://www.mfer.uz" + link.attr("href"));
String url = "http://www.mfer.uz" + link.attr("href");
doc = Jsoup.connect("http://www.mfer.uz" + link.attr("href")).get();

if(!doc.title().toString().equals("МВЭСИТ - Новости Узбекистана"))
{
news.setUrl(url);
news.setTitle(doc.title());
news.setEntity("МВЭСИТ");
news.setNewsText("");
//news.setNewsDate(new Date());
//System.out.println("Title: " + doc.title());
Elements paragraphs = doc.select("div.detail-text").first().select("div ");
int i = 0;
for(Element p :paragraphs)
{
i += 1;
if(i != 1)
{
news.setNewsText(news.getNewsText() +"<br />\n" + p.text());
//System.out.println(p.text());
}
}
parsingService.addNews(news);
}

}

}
}
catch(IOException e)
{
e.printStackTrace();
}
}

我的错误日志

    2016-08-03 22:22:53.147  WARN 4620 --- [pool-2-thread-1] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 42P01
2016-08-03 22:22:53.147 ERROR 4620 --- [pool-2-thread-1] o.h.engine.jdbc.spi.SqlExceptionHelper : ERROR: relation "hibernate_sequences" does not exist
Позиция: 36
2016-08-03 22:22:53.162 ERROR 4620 --- [pool-2-thread-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task.

org.springframework.dao.InvalidDataAccessResourceUsageException: error performing isolated work; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: error performing isolated work
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:242) ~[spring-orm-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:225) ~[spring-orm-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:436) ~[spring-orm-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) ~[spring-tx-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) ~[spring-tx-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147) ~[spring-tx-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:131) ~[spring-data-jpa-1.9.4.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-4.2.7.RELEASE.jar:4.2.7.RELEASE]
at com.sun.proxy.$Proxy75.save(Unknown Source) ~[na:na]

我几乎过去 2 天都在解决这个问题。

我在这个问题上苦苦思索了将近 2 天。我想问题出在@GeneratedValue 和策略上。

最佳答案

尝试替换 IDENTITY 上的策略,如下所示:

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Long id;

关于spring - Spring Boot Batch 中的 Hibernate_sequence 错误(预定),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38750127/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com