【问题标题】:spring mysql: Data truncation (data too long for column)spring mysql:数据截断(列的数据太长)
【发布时间】:2015-10-15 02:09:04
【问题描述】:

我有我的班级电影:

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

【问题讨论】:

  • 你查过数据库中列的长度是多少?

标签: java spring hibernate spring-mvc


【解决方案1】:

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

它可能适用于此。我已经遇到了这个错误。

【讨论】:

    【解决方案2】:

    我有SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement 异常。我有Date 列,只是将输入语法从2003-09-17 00:00:00 更改为17.09.2003。问题解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-14
      • 1970-01-01
      • 2017-01-03
      • 1970-01-01
      • 2014-02-26
      • 1970-01-01
      • 2022-11-26
      • 1970-01-01
      相关资源
      最近更新 更多