【发布时间】:2015-03-01 07:26:13
【问题描述】:
所以我写了这个,但是它在 Spring Boot 1.2.0 中破坏了,不知道为什么它在 1.1.9 中起作用(或看起来)
package com.xenoterracide.rpf.infrastructure.db;
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
import org.hibernate.type.PostgresUUIDType;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.UUIDTypeDescriptor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.Properties;
public class UUIDCustomType extends AbstractSingleColumnStandardBasicType {
public static final String UUID = "uuid-custom";
private static final Logger log = LoggerFactory.getLogger( UUIDCustomType.class );
private static final long serialVersionUID = 902830399800029445L;
private static final SqlTypeDescriptor SQL_DESCRIPTOR;
private static final JavaTypeDescriptor TYPE_DESCRIPTOR;
static {
Properties properties = new Properties();
try {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
properties.load( loader.getResourceAsStream( "database.properties" ) );
}
catch ( IOException e ) {
throw new RuntimeException( "Could not load properties!", e );
}
String dialect = properties.getProperty( "dialect" );
SQL_DESCRIPTOR
= dialect.equals( "org.hibernate.dialect.PostgreSQLDialect" )
? PostgresUUIDType.PostgresUUIDSqlTypeDescriptor.INSTANCE
: VarcharTypeDescriptor.INSTANCE;
log.debug( "dialect {}", dialect );
TYPE_DESCRIPTOR = UUIDTypeDescriptor.INSTANCE;
}
public UUIDCustomType() {
super(SQL_DESCRIPTOR, TYPE_DESCRIPTOR);
}
@Override
public String getName() {
return UUID;
}
}
破looks like it might have something to do with attempting to get the nonexistant properties file。
我如何从 Hibernate 或 Spring 中获取方言?
【问题讨论】:
标签: java spring hibernate spring-boot