JPA: how do I persist a String into a database field, type MYSQL Text

Viewed 158677

The requirement is that the user can write an article, therefore I choose type Text for the content field inside mysql database. How can I convert Java String into MySQL Text

Here you go Jim Tough

@Entity
public class Article implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    private Long userId;

    private String title;

    private String content;

    private Integer vote;

    //Constructors, setters, getters, equals and hashcode
}

In my MYSQL database, content is type Text. I was hoping that there would be something like this java.sql.Text, since java.sql.Blob is an actual type, but sadly, that does not exist

3 Answers
Related