-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: UserType please help
PostPosted: Fri Mar 11, 2005 5:25 am 
Regular
Regular

Joined: Thu Feb 24, 2005 2:34 pm
Posts: 80
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 8:33 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
public abstract class TrimmedString


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 8:35 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
BTW - I checked the url that you supplied. The code is correct. There is no mention of an abstract class.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 11, 2005 8:49 am 
Regular
Regular

Joined: Thu Feb 24, 2005 2:34 pm
Posts: 80
Ok , i found my problem, here the correct code, using hibernate 3 i need to override these methods

hashCode
assemble
disassmeble
replace

but in the link that i found don't override these methods, then the code work fine.
Thank's for you help
Devis

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.*;
import java.io.Serializable;
/**
* @author Colin Hawkett
*/
public class TrimmedString implements UserType,Serializable
{
    public TrimmedString() {
        super();
    }

    public int[] sqlTypes() {
        return new int[] { Types.VARCHAR };
    }

    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]);
          System.out.println("Codice cmpf originale "+val );
        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;
    }


public int hashCode(Object x) throws HibernateException {
return x.hashCode();
}

public Object assemble(Serializable cached, Object owner)
throws HibernateException {
return cached;
}

public Serializable disassemble(Object value) throws HibernateException {
return (Serializable) value;
}

public Object replace(Object original, Object target, Object owner)
throws HibernateException {
return original;
}


}



Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.