-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate3.1: How to use Custom Identifier?
PostPosted: Tue Dec 20, 2005 4:41 pm 
Beginner
Beginner

Joined: Tue Nov 15, 2005 6:56 pm
Posts: 39
Using: Hibernate3.1, Hibernate-tools3.1beta2, Oracle10g.

    Attempting to upgrade from Hibernate3.0 to Hibernate3.1. This all used to work before the upgrade.

    Having a problem starting up my application in JBOSS server (It's a JBOSS service). I get the folowing errors (the lines marked with ">>>>" are my own debug lines). Essentially it's having problems with a custom identifer in one of my mapping files. After debugging the Hibernate3.1 source, I found that the dialect "Oracle9Dialect" can't find the type for custom identifier (specifically, in file TypeNames.java at method get()).


The exceptions I get are:


Code:
>>>> About to call contextClassLoader for com.util.common.type.GuidType
[2005-12-20 12:07:53,490] - main  - INFO  - ing.util.LoggerStream.write(LoggerStream.java:140) - >>>> After calling contextClassLoader
[2005-12-20 12:14:24,436] - main  - INFO  - rnateService.start(MyCompanyHibernateService.java:115) - Could not build SessionFactory using the MBean classpath - will try again using client classpath: No Dialect mapping for JDBC type: -2
...
>>>> About to call contextClassLoader for com.util.common.type.GuidType
[2005-12-20 12:21:37,593] - main  - INFO  - ing.util.LoggerStream.write(LoggerStream.java:140) - >>>> After calling contextClassLoader
[2005-12-20 12:22:00,136] - main  - WARN  - erviceController.start(ServiceController.java:429) - Problem starting service MyCompany.com:service=LogHibernate
org.hibernate.HibernateException: org.hibernate.MappingException: No Dialect mapping for JDBC type: -2
   at com.util.common.jmx.MyCompanyHibernateService.start(MyCompanyHibernateService.java:135)
   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:585)
   at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
   at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:914)
   at $Proxy0.start(Unknown Source)
   at org.jboss.system.ServiceController.start(ServiceController.java:418)
   at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
   at $Proxy4.start(Unknown Source)
   at org.jboss.deployment.SARDeployer.start(SARDeployer.java:273)
   at org.jboss.deployment.MainDeployer.start(MainDeployer.java:964)
   at org.jboss.deployment.MainDeployer.start(MainDeployer.java:956)
   at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:775)
   at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:738)
   at sun.reflect.GeneratedMethodAccessor45.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
   at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:121)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
   at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:127)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
   at $Proxy8.deploy(Unknown Source)
   at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:325)
   at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:501)
   at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:204)
   at org.jboss.deployment.scanner.AbstractDeploymentScanner.startService(AbstractDeploymentScanner.java:277)
   at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:272)
   at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:222)
   at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
   at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:897)
   at $Proxy0.start(Unknown Source)
   at org.jboss.system.ServiceController.start(ServiceController.java:418)
   at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:72)
   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
   at $Proxy4.start(Unknown Source)
   at org.jboss.deployment.SARDeployer.start(SARDeployer.java:273)
   at org.jboss.deployment.MainDeployer.start(MainDeployer.java:964)
   at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:775)
   at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:738)
   at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:722)
   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:585)
   at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:141)
   at org.jboss.mx.server.Invocation.dispatch(Invocation.java:80)
   at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:121)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
   at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:127)
   at org.jboss.mx.server.Invocation.invoke(Invocation.java:74)
   at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:249)
   at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:644)
   at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:177)
   at $Proxy5.deploy(Unknown Source)
   at org.jboss.system.server.ServerImpl.doStart(ServerImpl.java:434)
   at org.jboss.system.server.ServerImpl.start(ServerImpl.java:315)
   at org.jboss.Main.boot(Main.java:195)
   at org.jboss.Main$1.run(Main.java:463)
   at java.lang.Thread.run(Thread.java:595)
Caused by: org.hibernate.MappingException: No Dialect mapping for JDBC type: -2
   at org.hibernate.dialect.TypeNames.get(TypeNames.java:56)
   at org.hibernate.dialect.TypeNames.get(TypeNames.java:81)
   at org.hibernate.dialect.Dialect.getTypeName(Dialect.java:216)
   at org.hibernate.mapping.Column.getSqlType(Column.java:181)
   at org.hibernate.mapping.Table.sqlTemporaryTableCreateString(Table.java:302)
   at org.hibernate.mapping.PersistentClass.prepareTemporaryTables(PersistentClass.java:636)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:199)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1167)
   at com.util.common.jmx.MyCompanyHibernateService.internalBuildSessionFactory(MyCompanyHibernateService.java:102)
   at com.util.common.jmx.SessionFactoryStub.getImpl(SessionFactoryStub.java:79)
   at com.util.common.jmx.SessionFactoryStub.getStatistics(SessionFactoryStub.java:177)
   at org.hibernate.jmx.StatisticsService.setSessionFactory(StatisticsService.java:108)
   at org.hibernate.jmx.StatisticsService.setSessionFactoryJNDIName(StatisticsService.java:78)
   at com.util.common.jmx.MyCompanyHibernateService.start(MyCompanyHibernateService.java:130)
   ... 91 more


Specifically, the lines in the above exceptions that may hint at some problem are:

Code:
Could not build SessionFactory using the MBean classpath - will try again using client classpath: No Dialect mapping for JDBC type: -2
...
Problem starting service MyCompany.com:service=LogHibernate
org.hibernate.HibernateException: org.hibernate.MappingException: No Dialect mapping for JDBC type: -2



The identifier definition in my mapping file:

Code:
       <id name="evtLogId" type="mycompany.util.common.type.GuidType">
         <generator class="mycompany.util.common.id.GuidIdentifierGenerator"/>
      </id>



The method in TypeNames.java that is having trouble finding the type for the identifier:


Code:
   public String get(int typecode) throws MappingException {
      String result = (String) defaults.get( new Integer(typecode) );
      if (result==null) throw new MappingException("No Dialect mapping for JDBC type: " + typecode);
      return result;
   }


Any help would be appreciated.

Thank You.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 6:18 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
Are you trying to use BINARY type for sqlTypes() return in the GuidType?
Use VARBINARY instead.

or, post the GuidType code.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 7:42 pm 
Beginner
Beginner

Joined: Tue Nov 15, 2005 6:56 pm
Posts: 39
I didn't write the code, so I'm not exactly sure what you mean. However, below is the code for GUIDType.

Code:
public class GuidType implements UserType, Serializable {
   
   private static final long serialVersionUID = 1L;

   private static final int[]  SQL_TYPES = {OracleTypes.RAW  };
   
    public int[] sqlTypes()
    {
        return SQL_TYPES;
    }

    public Class returnedClass()
    {
        return Guid.class;
    }

   public boolean equals(Object x, Object y) throws HibernateException {
        if ( x == y ) return true;
        if ( x == null || y == null) return false;
       
        return x.equals(y);
   }

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

   public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
        byte[] b = rs.getBytes(names[0]);

      if (b == null)
         return null;
      
        return new Guid(b);
   }

   public void nullSafeSet(PreparedStatement stmt, Object value, int index) throws HibernateException, SQLException {
      if (value == null) {
         stmt.setNull(index, OracleTypes.RAW);
      }
      else {
            Guid guid = null;
            if (value instanceof String) {
                guid = new Guid((String)value);   
            } else {
             guid = (Guid)value;
            }
         stmt.setBytes(index,guid.toBytes());
      }
   }

    public Object deepCopy(Object value) throws HibernateException
    {
        return value;
    }

    public boolean isMutable()
    {
        return true;
    }

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

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

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 20, 2005 8:04 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
replace
private static final int[] SQL_TYPES = {OracleTypes.RAW };
with
private static final int[] TYPES = new int[] { Types.VARBINARY };


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 21, 2005 4:19 pm 
Beginner
Beginner

Joined: Tue Nov 15, 2005 6:56 pm
Posts: 39
Thanks! That solved that problem! Of course, now I'm onto my next set of exceptions with my upgrade to Hibernate 3.1. I'm getting problems with named queries.

If you have any knowledge about named query exceptions with the new HIbernate 3.1, I've posted it at http://forum.hibernate.org/viewtopic.php?t=951569

Thanks again for your help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.