V
V
Virgil Merkel2020-10-09 10:05:56
Hibernate
Virgil Merkel, 2020-10-09 10:05:56

How to change column type in postgresql via spring boot?

I have such an entity

import javax.persistence.*;

@Entity
public class RatingList {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String message;
    private Double rating;

    // связи на отправителя
    // и на препода
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "user_id")
    private User author;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "teacher_id")
    private Teacher teacher;


    public RatingList() {
    }


    public RatingList(String message, Double rating, User author, Teacher teacher) {
        this.message = message;
        this.rating = rating;
        this.author = author;
        this.teacher = teacher;
    }

    public Long getId() {
        return id;
    }

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

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Double getRating() {
        return rating;
    }

    public void setRating(Double rating) {
        this.rating = rating;
    }

    public User getAuthor() {
        return author;
    }

    public void setAuthor(User author) {
        this.author = author;
    }

    public Teacher getTeacher() {
        return teacher;
    }

    public void setTeacher(Teacher teacher) {
        this.teacher = teacher;
    }


In my database, for message spring, I selected the field type varchar (255), when a request of 20 words arrives, I get an error. How can I make it so that the type of text is set in the database?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan Hasanli, 2020-10-09
@blrmyfc

Hello!
You can set length. For example,

@Column (length = 2000)
private String message;

https://www.baeldung.com/jpa-size-length-column-di...
or
Use @Lob
https://www.baeldung.com/hibernate-lob annotation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question