2016-08-03 24 views
1

Ich habe interessante Situation. Ich habe mehrere News-Posting-Websites analysiert und möchte sie über den Scheduler in der Datenbank speichern. Der Fehler tritt jedoch beim Speichern auf. Aufgrund der transaktionalen Write-Behind-Bedingung described here.Hibernate_sequence Fehler in Spring Boot Batch (geplant)

Meine Modellklasse ist

@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} 

meine Hibernate Einstellungen (Frühjahr Boot diejenigen)

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 

Meine Feder Batch geplante Methode

@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(); 
     } 
    } 

mein Fehlerlogs

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] 

Ich stacke in diesem Problem fast 2 Tage.

Ich bin in diesem Problem fast 2 Tage gestapelt. Ich nehme an, dass das Problem bei @GeneratedValue und der Strategie liegt.

+0

Versuchen Datentyp 'Long' zu' long' ändern. Du brauchst es nicht, um 'Long' zu sein – ryekayo

+0

ist es ein Grund oder eine Änderung für eine gute Code-Praxis? – ISkandar

+0

Nun Long erlaubt Nullwerte. Da Sie Spring/Hibernate verwenden und davon ausgehen, dass Ihre ID Ihre PK ist, sollten Sie KEINE Nullwerte haben. Ich denke nur, dass es besser ist, diese in '' zu ändern lang " – ryekayo

Antwort

0

Try Strategie auf Identität, wie diese zu ersetzen:

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