Should I be able to simply map a java.lang.String property as type="text", have the string data stored as a CLOB and read and write to that field?
The data in the java.lang.String is a bas64-encoded GIF file. With one version of the JayBird JDBC driver I get the "charsetName" exception when I try to read the data back. When I retried with their latest driver, the exception occured while trying to save the data.
I've seen info about special CLOB handling for Oracle, etc., so I thought I should first ask if I need to do more than map a String as "text" for this to work.
I don't see a place in the mapping to specify a character set, and both InputStreamReader and OutputStreamWriter appear to have a constructor that takes no character set and uses the system default.
Any help/redirection appreciated,
-Jeff
Hibernate version: 3.0.5
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="com.lexmark.workflow.framework.domain.welcome.ButtonDescriptionImpl"
dynamic-update="false"
dynamic-insert="false"
table="WELCOME_BUTTON"
discriminator-value="Base">
<id name="id"
column="BUTTON_ID"
type="java.lang.Long"
unsaved-value="null">
<generator class="hilo">
</generator>
</id>
<discriminator column="CLASS_DISC" type="string"/>
<property name="profileName"
type="java.lang.String"
column="PROFILENAME"
length="25"/>
<property name="iconText"
type="java.lang.String"
column="ICONTEXT"
length="25"/>
<property name="type"
type="java.lang.String"
column="BUTTON_TYPE"
length="20"/>
<property name="upIcon"
type="text"
column="UPICON"/>
<subclass name="com.lexmark.workflow.framework.domain.welcome.MaconButtonDescription" discriminator-value="M"/>
<subclass name="com.lexmark.workflow.framework.domain.welcome.MonteCarloButtonDescription" discriminator-value="MC">
<property name="downIcon"
type="text"
column="DOWNICON"/>
<property name="persist"
type="boolean"
column="PERSIST"/>
</subclass>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="com.lexmark.workflow.framework.domain.welcome.WelcomeScreenLayoutImpl"
dynamic-update="false"
dynamic-insert="false"
table="WELCOME_LAYOUT"
discriminator-value="Base">
<id name="id"
column="LAYOUT_ID"
type="java.lang.Long"
unsaved-value="null">
<generator class="hilo">
</generator>
</id>
<discriminator column="CLASS_DISC" type="string"/>
<property name="numFirstPageButtons"
type="java.lang.Integer"
column="NUMFIRSTPAGEBUTTONS"/>
<list name="buttons" lazy="false" table="LAYOUTS_HAVE_BUTTONS"
cascade="save-update">
<key>
<column name="LAYOUT_ID"/>
</key>
<index column="LISTPOSITION"/>
<many-to-many class="com.lexmark.workflow.framework.domain.welcome.ButtonDescriptionImpl" column="BUTTON_ID"/>
</list>
<subclass name="com.lexmark.workflow.framework.domain.welcome.MaconScreenLayout" discriminator-value="M"/>
<subclass name="com.lexmark.workflow.framework.domain.welcome.MonteCarloScreenLayout" discriminator-value="MC">
<property name="layoutType"
type="java.lang.String"
column="LAYOUTTYPE"
length="20"/>
</subclass>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
getHibernateTemplate().saveOrUpdate(layout);
Full stack trace of any exception that occurs:
java.lang.NullPointerException: charsetName
at java.io.OutputStreamWriter.<init>(Unknown Source)
at org.firebirdsql.jdbc.FBBlob.copyCharacterStream(FBBlob.java:544)
at org.firebirdsql.jdbc.field.FBLongVarCharField.copyCharacterStream(FBLongVarCharField.java:237)
at org.firebirdsql.jdbc.field.FBLongVarCharField.flushCachedData(FBLongVarCharField.java:214)
at org.firebirdsql.jdbc.AbstractPreparedStatement.flushFields(AbstractPreparedStatement.java:723)
at org.firebirdsql.jdbc.AbstractPreparedStatement.internalExecute(AbstractPreparedStatement.java:697)
at org.firebirdsql.jdbc.AbstractPreparedStatement.executeUpdate(AbstractPreparedStatement.java:164)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:94)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1853)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:490)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:495)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:468)
at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:258)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy8.saveWelcomeScreen(Unknown Source)
at com.lexmark.workflow.framework.tools.DataLoader.loadMonteCarloWelcomeScreen(DataLoader.java:396)
at com.lexmark.workflow.framework.tools.DataLoader.loadWelcomeScreens(DataLoader.java:480)
at com.lexmark.workflow.framework.tools.DataLoader.loadAllData(DataLoader.java:164)
at com.lexmark.workflow.framework.tools.DataLoader.main(DataLoader.java:543)
Name and version of the database you are using:
Firebird 1.5.2
The generated SQL (show_sql=true):
Hibernate: insert into WELCOME_LAYOUT (NUMFIRSTPAGEBUTTONS, LAYOUTTYPE, CLASS_DISC, LAYOUT_ID) values (?, ?, 'MC', ?)
Hibernate: insert into WELCOME_BUTTON (PROFILENAME, ICONTEXT, BUTTON_TYPE, UPICON, DOWNICON, PERSIST, CLASS_DISC, BUTTON_ID) values (?, ?, ?, ?, ?, ?, 'MC', ?)