private void registerTypes(final TypeContributions typeContributions) { typeContributions.contributeType(new OrderUserType() { @Override public void nullSafeSet(final PreparedStatement statement, final Object value, final int index, final SessionImplementor session) throws SQLException { try { statement.setObject(index, jaxbToString(value)); } catch (JAXBException e) { throw new SQLException("Could not set test Order", e); } } }, new String[]{"Order"}); }
private SessionFactory newSessionFactory() { Properties properties = properties(); Configuration configuration = new Configuration().addProperties(properties); for (Class<?> entityClass : entities()) { configuration.addAnnotatedClass(entityClass); } String[] packages = packages(); if (packages != null) { for (String scannedPackage : packages) { configuration.addPackage(scannedPackage); } } String[] resources = resources(); if (resources != null) { for (String resource : resources) { configuration.addResource(resource); } } Interceptor interceptor = interceptor(); if (interceptor != null) { configuration.setInterceptor(interceptor); } final List<Type> additionalTypes = additionalTypes(); if (additionalTypes != null) { configuration.registerTypeContributor(new TypeContributor() { @Override public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { for (Type type : additionalTypes) { if (type instanceof BasicType) { typeContributions.contributeType((BasicType) type); } else if (type instanceof UserType) { typeContributions.contributeType((UserType) type, new String[]{type.getName()}); } else if (type instanceof CompositeUserType) { typeContributions.contributeType((CompositeUserType) type, new String[]{type.getName()}); } } } }); } return configuration.buildSessionFactory( new StandardServiceRegistryBuilder() .applySettings(properties) .build() ); }
@Override public void contributeTypes(final TypeContributions typeContributions, final ServiceRegistry serviceRegistry) { super.contributeTypes(typeContributions, serviceRegistry); registerTypes(typeContributions); }
private void registerTypes(final TypeContributions typeContributions) { typeContributions.contributeType(new OrderUserType(), new String[]{"Order"}); }
/** * Allows the Dialect to contribute additional types * * @param typeContributions Callback to contribute the types * @param serviceRegistry The service registry */ public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { // by default, nothing to do }