spring mysql:数据截断(列的数据太长)

时间:2015-07-24 11:53:16

标签: java spring hibernate spring-mvc

我有我的班级电影:

@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 [springDispatcher]的Servlet.service()在上下文中与路径[/ web-programming]引发异常[请求处理失败;嵌套异常是org.springframework.dao.DataIntegrityViolationException:无法执行语句; SQL [不适用];嵌套异常是org.hibernate.exception.DataException:无法执行语句的根本原因   com.mysql.jdbc.MysqlDataTruncation:数据截断:第1行的列'overview'的数据太长

2 个答案:

答案 0 :(得分:0)

在MySql中,如果列类型为varchar,则更改表格,然后将其更改为text。除了文本之外,MySql中有许多数据类型。与MEDIUM TEXTLONGTEXT

相同

enter image description here

这可能是有用的。我已经面临这个错误了。

答案 1 :(得分:0)

我有Doctor summary (to see all details, run flutter doctor -v): [√] Flutter (Channel stable, v1.12.13+hotfix.5, on Microsoft Windows [Version 10.0.18362.778], locale fa-IR) [√] Android toolchain `enter code here`- develop for Android devices (Android SDK version 29.0.3) [√] Android Studio (version 3.5) [!] Connected device ! No devices available ! Doctor found issues in 1 category. 个例外。我有SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement列,只是将输入语法从Date更改为2003-09-17 00:00:00。问题解决了。