Hibernate or hsql does not respect column length

点点圈 提交于 2019-12-23 00:48:09

问题


I have an application that uses hibernate to generate tables (since my application is still under development) for HSQL db. In my domain model I have set

@Basic
@Column(name = "about", length = 10)
private String about;

When I open my db using DBVisualizer I can see that everything is set up properly except it is not working my column accepts values that are way over 10 characters long. When I try to run the query manually in the DBVisualier it fails as it should but hibernate lets it run.

Also very strange is when I use the file (in stead of in memory db) so that I can see the db structure and I point to the DBVisualizer it somehow breaks the connection so my changes from the Hibernate are not visible from that moment on. Everything still works I just cant see that changes in the DBVisualizer but I can in the application.

Anyone has any idea about this weird behavior?

cheers all

UPDATE

Hibernate configuration

    <property name="hibernate.connection.driver_class">org.hsqldb.jdbcDriver</property>
    <property name="hibernate.connection.url">jdbc:hsqldb:mem:test</property>
    <property name="hibernate.connection.username">sa</property>
    <property name="hibernate.connection.password"></property>
    <property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
    <property name="hbm2ddl.auto">create</property>
    <property name="sql.enforce_strict_size">true</property>

回答1:


Your problem probably comes from a limitation in HSQLDB, described in the documentation:

HSQLDB databases are initially created in a legacy mode that does not enforce column size and precision. You can set the property: sql.enforce_strict_size=true to enable this feature. When this property has been set, Any supplied column size and precision for numeric and character types (CHARACTER and VARCHAR) are enforced. Use the command, SET PROPERTY "sql.enforce_strict_size" TRUE once before defining the tables.

(emphasis mine)



来源:https://stackoverflow.com/questions/10765796/hibernate-or-hsql-does-not-respect-column-length

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!