1
私は興味深い状況があります。私はいくつかのニュース投稿ウェブサイトを解析し、それらをスケジューラを通してデータベースに保存したいと思っています。しかし、保存中にエラーが発生します。トランザクションの後書き条件described hereのためです。SpringブートバッチでHibernate_sequenceエラー(予定)
私のモデルクラスは
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
私の春のバッチ予定方式
@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();
}
}
私のエラーログ
@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}
私の休止状態の設定
(春ブーツのもの)である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と戦略の周りにあると考えています。
long' 'にデータ型' Long'を変更してみてください。あなたはそれが 'ロング 'である必要はありません – ryekayo
良いコードプラクティスの理由か変更ですか? – ISkandar
Well Longはnull値を許します。あなたはSpring/Hibernateを使用しており、IDがあなたのPKであると推測しているので、ヌル値を持つべきではありません。私はそれを '長い – ryekayo