Hibernate column designation for TEXT

I have a spring MVC boot application with a MySQL database and I am trying to get the TEXT field in my database. I have the following code:

Member.java

@Entity
public class Member {
private Long id;
private String name;

@Column(columnDefinition = "TEXT")
private String biography;

private String country;
private String state;
private String city;
private Date dateOfBirth;
private String gender;

//Getters and setters

application.properties

spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.show-sql=true
spring.datasource.url=jdbc:mysql://localhost:3306/wave
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=mysql
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
spring.h2.console.enabled=true

And so Hibernate creates

Hibernate: drop table if exists member
Hibernate: create table member (id bigint not null auto_increment, biography varchar(255), city varchar(255), country varchar(255), date_of_birth date, gender varchar(255), name varchar(255), state varchar(255), primary key (id)) ENGINE=InnoDB

He still sets it as varchar (255). Can someone help me with this problem? Thank you in advance.

+10
source share
3 answers

You can use @Lobfrom javax.persistence ... this is more elegant:

@Column
@Lob
public String getDescription() {...
+8
source

There org.hibernate.dialect.MySQLDialectis a line in the class :

registerColumnType( Types.CLOB, 65535, "text" );

, , :

@Column(length = 65535, columnDefinition = "text")
private String biography;

.

+6

Deleting a column definition may solve the problem (just annotate using @Columnhibernate is smart to figure it out), but varcharis a replacement textin newer versions of sql servers, so I think there is nothing wrong with using it varchar. (255) is the default length.

0
source

Source: https://habr.com/ru/post/1675186/


All Articles