Hibernate version:3.rc1
Hi i'm new to use UserType i have found this code in Hibernate documentation
http://www.hibernate.org/Documentation/ ... 2AndOracle
Code:
package dao.hibernate;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.*;
import org.hibernate.usertype.*;
/**
* @author Colin Hawkett
*/
public abstract class TrimmedString implements UserType,Comparable,
java.io.Serializable {
public TrimmedString() {
super();
}
public int[] sqlTypes() {
return new int[] { Types.CHAR };
}
public Class returnedClass() {
return String.class;
}
public boolean equals(Object x, Object y) throws HibernateException {
return (x == y) || (x != null && y != null && (x.equals(y)));
}
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
String val = rs.getString(names[0]);
return val != null ? val.trim() : null;
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
st.setString(index, (String)value);
}
public Object deepCopy(Object value) throws HibernateException {
if (value == null) return null;
return new String((String)value);
}
public boolean isMutable() {
return false;
}
}
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="vo.as400.CCmpf" table="sdgtwb_dat.arctb00f" lazy="false" where ="cdtbtb in ('CMP')">
<composite-id>
<key-property name="tpo_tbl" column="cdtbtb"/>
<key-property name="cdc_cmpf" column="cdeltb" type="dao.hibernate.TrimmedString"/>
</composite-id>
<property name="dsc_cmpf" column="DATITB" type="string" />
</class>
</hibernate-mapping>
But receive this error.
org.hibernate.MappingException: Cannot instantiate custom type: dao.hibernate.TrimmedString
at org.hibernate.type.CustomType.<init>(CustomType.java:48)
at org.hibernate.type.TypeFactory.heuristicType(TypeFactory.java:183)
at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:214)
at org.hibernate.mapping.Property.getType(Property.java:47)
at org.hibernate.mapping.Component.getType(Component.java:150)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:207)
at org.hibernate.mapping.RootClass.validate(RootClass.java:187)
at org.hibernate.cfg.Configuration.validate(Configuration.java:814)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1037)
at database.AS400Session.<clinit>(AS400Session.java:30)
at workflow.WFCampionario.Test_AS400(WFCampionario.java:61)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at flashgateway.adapter.java.JavaBeanAdapter.invokeFunction(JavaBeanAdapter.java:65)
at flashgateway.filter.AdapterFilter.invoke(AdapterFilter.java:117)
at flashgateway.filter.MessageSecurityFilter.invoke(MessageSecurityFilter.java:144)
at flashgateway.filter.ServiceNameFilter.invoke(ServiceNameFilter.java:101)
at flashgateway.filter.EnvelopeFilter.invoke(EnvelopeFilter.java:102)
at flashgateway.filter.SessionFilter.invoke(SessionFilter.java:28)
at flashgateway.filter.LicenseFilter.invoke(LicenseFilter.java:57)
at flashgateway.filter.ErrorFilter.invoke(ErrorFilter.java:39)
at flashgateway.filter.LogFilter.invoke(LogFilter.java:46)
at flashgateway.filter.BatchProcessFilter.invoke(BatchProcessFilter.java:63)
at flashgateway.filter.PacketSecurityFilter.invoke(PacketSecurityFilter.java:68)
at flashgateway.filter.DebugFilter.invoke(DebugFilter.java:38)
at flashgateway.filter.SerializationFilter.invoke(SerializationFilter.java:89)
at flashgateway.Gateway.invoke(Gateway.java:217)
at flashgateway.controller.GatewayServlet.service(GatewayServlet.java:69)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:534)
10:05:27,241 FATAL AS400Session:34 - Cannot instantiate custom type: dao.hibernate.TrimmedString
13530 [Thread-11] FATAL database.AS400Session - Cannot instantiate custom type: dao.hibernate.TrimmedString
Error: Configuration problemCannot instantiate custom type: dao.hibernate.TrimmedString
What's wrong please, can you help me...
Devis