Issue Details (XML | Word | Printable)

Key: HHH-2354
Type: Bug Bug
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Zeljko Trogrlic
Votes: 1
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Hibernate Core

Schema validation too rigid for MySql enums

Created: 11/Jan/07 04:35 AM   Updated: 20/Jan/09 10:16 AM
Component/s: metamodel
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Not Specified

Environment: jboss-seam-1.1.0.GA, MySQL 5
Issue Links:
Relates
 


 Description  « Hide
Enum column type in MySQL is handled as CHAR in their JDBC driver and should be mapped to String Java type.
However, Hibernate expects varchar(n) and fails to do the validation.

This is how DatabaseMetaData.getColumns describes it:

DATA_TYPE=1
TYPE_NAME=enum

Note that although TYPE_NAME is enum, DATA_TYPE represents CHAR.

Hibernate reports following exception:

13:49:31,397 INFO [TableMetadata] table found: configuration.userdb_domain_acl
13:49:31,397 INFO [TableMetadata] columns: [id, enabled, tablename, domain]
13:49:31,397 WARN [ServiceController] Problem starting service persistence.units:ear=msmgui.ear,unitName=msmgui
javax.persistence.PersistenceException: org.hibernate.HibernateException: Wrong column type: enabled, expected: varchar(
2)
        at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:698)
        at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:127)
        at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:264)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

Validation should be fixed/relaxed to avoid this problem.

 All   Comments   Work Log   Change History   FishEye      Sort Order: Ascending order - Click to sort in descending order
Zeljko Trogrlic added a comment - 11/Jan/07 04:38 AM
Workaround: Disable schema validation by commenting following line in persistence.xml:
<!--property name="hibernate.hbm2ddl.auto" value="validate"/-->

Alex Fuller added a comment - 20/Jan/09 10:16 AM
Another workaround if you're using JPA annotations is to add an @Column(columnDefinition="enum('val1', 'val2'... 'valN')") annotation. At least you can leave schema validation on. However this will not help if you are swapping between MySQL and another database for dev/test etc.