· 8 years ago · Aug 12, 2018, 04:16 PM
1@Column(length=1000000)
2@Lob
3private String notes;
4
5<property name="hibernate.hbm2ddl.auto" value="update" />
6
7import javax.persistence.Column;
8import javax.persistence.Entity;
9import javax.persistence.GeneratedValue;
10import javax.persistence.Id;
11import javax.persistence.Lob;
12import javax.persistence.NamedQuery;
13import javax.persistence.Table;
14
15@Entity
16@Table( name = "usr" )
17
18public class User {
19 @Id
20 @GeneratedValue
21 private Long id;
22
23 @Column( length = 40, unique = true )
24 private String name;
25
26 @Lob
27 @Column( length = 100000 )
28 private String text;
29
30 public long getId() {
31 return id;
32 }
33
34 public void setName( String name ) {
35 this.name = name;
36 }
37
38 public String getName() {
39 return name;
40 }
41
42 public String getText() {
43 return text;
44 }
45
46 public void setText( String text ) {
47 this.text = text;
48 }
49
50}
51
52<persistence xmlns="http://java.sun.com/xml/ns/persistence"
53 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
54 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
55 version="2.0">
56 <persistence-unit name="jpatest" transaction-type="RESOURCE_LOCAL">
57 <properties>
58 <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
59 <property name="hibernate.hbm2ddl.auto" value="update"/>
60 <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
61 <property name="hibernate.connection.username" value="root"/>
62 <property name="hibernate.connection.password" value="root"/>
63 <property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/jpadatabase"/>
64 <property name="hibernate.show-sql" value="true"/>
65 </properties>
66 </persistence-unit>
67</persistence>
68
69.....
70
71 @Column( length = 255 )
72 private String text;
73......
74
75DEBUG SchemaExport:415 - drop table if exists usr
76DEBUG SchemaExport:415 - create table usr (id bigint not null auto_increment, name varchar(40) unique, text varchar(255), primary key (id)) ENGINE=InnoDB
77INFO SchemaExport:281 - schema export complete
78
79.....
80@Lob
81@Column( length = 100000 )
82private String text;
83.......
84
85DEBUG SchemaExport:415 - drop table if exists usr
86DEBUG SchemaExport:415 - create table usr (id bigint not null auto_increment, name varchar(40) unique, text longtext, primary key (id)) ENGINE=InnoDB
87INFO SchemaExport:281 - schema export complete
88
89INFO TableMetadata:65 - table found: jpadatabase.usr
90 INFO TableMetadata:66 - columns: [id, text, name]
91 INFO TableMetadata:68 - foreign keys: []
92 INFO TableMetadata:69 - indexes: [name, primary]
93 DEBUG DefaultIdentifierGeneratorFactory:90 - Setting dialect [org.hibernate.dialect.MySQL5InnoDBDialect]
94 INFO SchemaUpdate:217 - schema update complete
95
96DEBUG SchemaUpdate:203 - alter table usr add column location varchar(255)
97INFO SchemaUpdate:217 - schema update complete
98
99ALTER TABLE piece_aud MODIFY notes LONGTEXT;
100
101ALTER TABLE piece_aud MODIFY notes LONGTEXT;
102
103<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy"/>
104
105alter table your_table modify column your_column text
106
107@Type(type="org.hibernate.type.StringClobType")
108String message;
109
110@Column(name="your_column_name",columnDefinition="LONGTEXT")
111private String notes;