Hibernate version: 3.2.4 sp1
Name and version of the database you are using: Firebird 1.5.3
Hello,
My problem is how use enum for id :
I have this enum :
Code:
public enum Day {
monday,
tuesday,
wednesday,
thursday,
friday,
saturday,
sunday
}
and this entity :
@Entity
@Table(name="WEEK")
public class Week {
@Id
@Enumerated(EnumType.STRING)
@Column(length=30)
private Day d;
@Column(length=30)
private String truc;
// + getters and setters
}
if I have in Hibernate configuration
<property name="hibernate.hbm2ddl.auto">create</property>
I get this error :
Quote:
GRAVE: Unsuccessful: create table WEEK (d blob not null, truc varchar(30), primary key (d))
If I create myself the table with this sql code :
Code:
create table WEEK (
d varchar(30) not null,
truc varchar(30));
alter table WEEK add constraint C_WEEK primary key(d);
<property name="hibernate.hbm2ddl.auto">update</property>
and I try to persist an Week entity instance, I get this error :
Quote:
Hibernate: insert into WEEK (truc, d) values (?, ?)
20 août 2007 11:27:46 org.hibernate.type.NullableType nullSafeSet
INFO: could not bind value '2c6d8085fef2809ce5f3f3e1e9aee5eef5ede5f2e1f4e9efeeaef3f4f2e9eee7aec4e1f98080808080808080928080f8f2808eeae1f6e1aeece1eee7aec5eef5ed8080808080808080928080f8f0f48086edefeee4e1f9' to parameter: 2; Data truncation
20 août 2007 11:27:46 org.hibernate.util.JDBCExceptionReporter logExceptions
ATTENTION: SQL Error: 0, SQLState: 01004
20 août 2007 11:27:46 org.hibernate.util.JDBCExceptionReporter logExceptions
GRAVE: Data truncation
20 août 2007 11:27:46 org.hibernate.event.def.AbstractFlushingEventListener performExecutions
GRAVE: Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: could not insert: [essai.enumeration.string.Week]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at essai.enumeration.string.WeekDao.create(WeekDao.java:14)
at essai.enumeration.string.Main.main(Main.java:16)
Caused by: java.sql.DataTruncation: Data truncation
at org.firebirdsql.jdbc.field.FBStringField.setBytes(FBStringField.java:341)
at org.firebirdsql.jdbc.AbstractPreparedStatement.setBytes(AbstractPreparedStatement.java:178)
at org.hibernate.type.AbstractBynaryType.set(AbstractBynaryType.java:43)
at org.hibernate.type.SerializableType.set(SerializableType.java:29)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:116)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2008)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2243)
... 12 more
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [essai.enumeration.string.Week]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at essai.enumeration.string.WeekDao.create(WeekDao.java:14)
at essai.enumeration.string.Main.main(Main.java:16)
Caused by: java.sql.DataTruncation: Data truncation
at org.firebirdsql.jdbc.field.FBStringField.setBytes(FBStringField.java:341)
at org.firebirdsql.jdbc.AbstractPreparedStatement.setBytes(AbstractPreparedStatement.java:178)
at org.hibernate.type.AbstractBynaryType.set(AbstractBynaryType.java:43)
at org.hibernate.type.SerializableType.set(SerializableType.java:29)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:136)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:116)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2008)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2243)
... 12 more
It seems that @Enumerated(STRING) is ignored.... I don't understand why.
If anyone have any ideas, thanks you for reply....