One of my entities Machinery
has got a String
property called notes
. JPA 2-Hibernate generates the schema for me, in my case the RDBMS is a MySQL.
notes
is created as a VARCHAR(255)
column, which is right.
Users begin to create records and all works perfectly, but then some users get the infamous Data too long for column "notes"
error.
That field hasn't enough room for user's machinery notes! Ok, no problem. Let's change the schema!
So, I open my entity class and change my property to:
@Column(length=1000000)
@Lob
private String notes;
By the way, my persistence.xml
declares:
<property name="hibernate.hbm2ddl.auto" value="update" />
After an application restart, I'm glad that Hibernate is altering my notes
column to a LONGTEXT
(it's enough for me).
So I first try using my application to create a new "long-noted" record and I still the the error "Data too long" although is a LONGTEXT
now.
Then, I try doing a raw INSERT
from the MySQL command line and it works! I can insert long notes in that field!
Finally, I DROP
my local/staging DB schema and change hibernate.hbm2ddl.auto
in persistence.xml
to create
and it works.
Does JPA still think that it's a VARCHAR
? Does it have some sort of cache or some place in which it stores schema's information?
I can't drop my production db, obviously. So, what can I do to reset or change the column type?
I am using JBossAS7 JPA 2-Hibernate.
NOTHING! I ended up with: - DB backup - hbm2ddl => CREATE-DROP - hbm2ddl => UPDATE - DB restore
Crazy! :(