2015-07-24 2 views
3

У меня есть класс фильм:весной MySQL: усечение данных (данные слишком долго для столбца)

@Entity 
@Table(name="movies") 

public class Movie { 

    private String genre_ids; 
    @Id 
    @GeneratedValue(strategy=GenerationType.IDENTITY) 
    private long id; 
    @Lob 
    @Column(length=1000000) 
    private String overview;  
    private String release_date; 
    private String poster_path; 
    private String popularity; 
    private String title; 

    public Movie() { 
     super(); 
     // TODO Auto-generated constructor stub 
    } 

    public String getGenre_ids() { 
     return genre_ids; 
    } 

    public void setGenre_ids(String genre_ids) { 
     this.genre_ids = genre_ids; 
    } 

    public long getId() { 
     return id; 
    } 

    public void setId(long id) { 
     this.id = id; 
    } 

    public String getOverview() { 
     return overview; 
    } 

    public void setOverview(String overview) { 
     this.overview = overview; 
    } 

    public String getRelease_date() { 
     return release_date; 
    } 

    public void setRelease_date(String release_date) { 
     this.release_date = release_date; 
    } 

    public String getPoster_path() { 
     return poster_path; 
    } 

    public void setPoster_path(String poster_path) { 
     this.poster_path = poster_path; 
    } 

    public String getPopularity() { 
     return popularity; 
    } 

    public void setPopularity(String popularity) { 
     this.popularity = popularity; 
    } 

    public String getTitle() { 
     return title; 
    } 

    public void setTitle(String title) { 
     this.title = title; 
    } 

    public Movie(String genre_ids, long id, String overview, String release_date, String poster_path, String popularity, 
      String title) { 
     super(); 
     this.genre_ids = genre_ids; 
     this.id = id; 
     this.overview = overview; 
     this.release_date = release_date; 
     this.poster_path = poster_path; 
     this.popularity = popularity; 
     this.title = title; 
    } 



} 

и мой метод контроллера:

@RequestMapping(value="/moviesPage",method=RequestMethod.GET) 

    public ModelAndView showMoviesPage() { 
      ModelAndView model=new ModelAndView("moviePage"); 
      try { 
       JSONObject json=readJsonFromUrl("http://api.themoviedb.org/3/discover/movie?api_key=cbb012e4e7ece74ac4c32a77b00a43eb&sort_by=popularity.desc&page=1"); 
       JSONArray array=json.getJSONArray("results"); 
       for(int i=0;i<array.length();i++) 
       { 
        JSONObject jsonMovie=array.getJSONObject(i); 
        Movie movie=new Movie(jsonMovie.getString("genre_ids"),jsonMovie.getLong("id"),jsonMovie.getString("overview"),jsonMovie.getString("release_date"),jsonMovie.getString("poster_path"),jsonMovie.getString("popularity"),jsonMovie.getString("title")); 
        movieServiceImpl.createMovie(movie); 
        System.out.println(movie); 
       } 
      } catch (IOException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (JSONException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      return model; } 

, и я получаю эту ошибку:

Servlet.service() for servlet [springDispatcher] in context with path [/web-programming] threw exception [Request processing failed; nested exception is org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement] with root cause com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'overview' at row 1

+2

Вы проверили, какая длина столбца в базе данных? –

ответ

0

В MySql измените таблицу, если тип столбца varchar, затем измените ее на text. В MySql есть много типов данных, кроме текста. Как MEDIUM TEXT, LONGTEXT и т.д.

enter image description here

Это может быть работа для этого. Я уже сталкивался с этой ошибкой.

Смежные вопросы