Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spring mysql: Data truncation (data too long for column)

I have my class Movie :

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



}

and my controller method:

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

and I'm getting this error:

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

like image 345
Hloro Fil Avatar asked Dec 10 '25 17:12

Hloro Fil


1 Answers

In MySql alter the table if column type is varchar then change it to text. There are many datatypes in MySql other then text. Like MEDIUM TEXT,LONGTEXT etc.

enter image description here

It may be work for that. I have already face this error.

like image 165
Avinash Mishra Avatar answered Dec 12 '25 07:12

Avinash Mishra