title: Hibernate 4.3.6 Glassfish 4 UserType Issue
body: <p>I'm migrating my application, working well on GlassFish 3.0.1 to Glassfish 4.0, and updating Hibernate as well, from 3.6 to 4.0. After a lot of migration issues, I'm stucked in this one:</p>
  
  <p>The application has several <code>org.hibernate.usertype.UserType</code> implementations. I'm aware of deprecation of <code>nullSafeGet</code> and <code>nullSafeSet</code>. Already correct all those, so, code compiles normally. Problem cames on deploy.</p>
  
  <p>On deploy (at the very beginning) I'm getting the following exception:</p>
  
  <pre><code>2014-08-31T12:43:22.312-0300|SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
  2014-08-31T12:43:22.313-0300|SEVERE: javax.persistence.PersistenceException: [PersistenceUnit: FOOEJB3DS] Unable to build Hibernate SessionFactory
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1225)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access$600(EntityManagerFactoryBuilderImpl.java:119)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:853)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
      at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
      at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
      at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:67)
      at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:199)
      at org.glassfish.persistence.jpa.PersistenceUnitLoader.&lt;init&gt;(PersistenceUnitLoader.java:107)
      at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:223)
      at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:510)
      at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:230)
      at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.prepareModule(ApplicationLifecycle.java:922)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:431)
      at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219)
      at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523)
      at java.security.AccessController.doPrivileged(Native Method)
      at javax.security.auth.Subject.doAs(Subject.java:356)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762)
      at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674)
      at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534)
      at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224)
      at org.glassfish.grizzly.http.server.StaticHttpHandler.service(StaticHttpHandler.java:297)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246)
      at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
      at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
      at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189)
      at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
      at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
      at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
      at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)
      at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
      at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564)
      at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)
      at java.lang.Thread.run(Thread.java:722)
  Caused by: org.hibernate.MappingException: Could not determine type for: br.com.MeasureUnitType, at table: item_itemcodes, for columns: [org.hibernate.mapping.Column(measureunit)]
      at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336)
      at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:310)
      at org.hibernate.mapping.Property.isValid(Property.java:241)
      at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:496)
      at org.hibernate.mapping.RootClass.validate(RootClass.java:270)
      at org.hibernate.cfg.Configuration.validate(Configuration.java:1358)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1849)
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
      ... 46 more
  </code></pre>
  
  <p>Analysing the initial exception <code>Caused by: org.hibernate.MappingException: Could not determine type for: br.com.foo.MeasureUnitType, at table: item_itemcodes, for columns: [org.hibernate.mapping.Column(measureunit)]</code> I can suppose something is wrong with my UserTypes. All the definitions are as they as working in previous GlassFish + Hibernate.</p>
  
  <p>Can't find anything about migration steps related to this (other than depracated methods mentioned before). Could read on Hibernate documentation <a href="http://docs.jboss.org/hibernate/orm/4.3/manual/en-US/html_single/#types-custom-type" rel="nofollow" title="TypeCustomTypeDoc">TypeCustomTypeDoc</a> something about registration of Custom Types. But, if I got this right, I just need to register if I want it to be default. In my case I'm declaring just using <code>@TypeDef</code>and <code>@Type</code> inside mey <code>@Entity</code> class.</p>
  
  <p>My Codes are following:</p>
  
  <pre><code>public class MeasureUnitType implements UserType {
      ... //Full Interface IMplementation (and working on previous environment)
  }
  </code></pre>
  
  <p>My Entity class:</p>
  
  <pre><code>@Entity
  @Table(name = "item_itemcodes")
  @TypeDef(name = "measureUnitType", typeClass = MeasureUnitType.class)
  public class ItemCodeVO extends FOODefaultVO {
    ...
    @Type(type = "measureUnitType")
    private MEASUREUNIT measureunit = null;
    ...
  }
  </code></pre>
  
  <p>Really appreciated any enlightenment!</p>
  
  <p>Thanks (Please feel free to correct my english to make it more understandable)</p>