n00b Java / hibernate问题。我想使用像这样定义的Hibernate来持久保存我的类DataStoreProvider -
class DataStoreProvider{
@ElementCollection
@MapKeyClass(value = NativeType.class)
protected ConcurrentHashMap<NativeType, ODBCType> nativeToODBC;
protected String name;
//getters and setters
}
引用的用户定义类定义如下 -
final public class NativeType {
private String name;
private int maxPrecision;
private byte maxScale;
public NativeType(String name, int maxPrecision, byte maxScale){
this.name = name;
this.maxPrecision = maxPrecision;
this.maxScale = maxScale;
}
// getters and setters
}
public enum ODBCType {
SQL_CHAR(1000000, 0),
SQL_VARCHAR(1000000, 0),
SQL_LONGVARCHAR(1000000, 0),
SQL_WCHAR(1000000, 0),
;
private final int maxPrecision;
private final int maxScale;
private ODBCType(int maxPrecision, int maxScale){
this.maxPrecision = maxPrecision;
this.maxScale = maxScale;
}
// getters and setters
}
NativeType在技术上仅在DataStoreProvider的上下文中具有标识。因此,如果需要,我可以将提供程序包含为NativeType的属性,以使其更清晰。当然,NativeType-DataStoreProvider的关系也是多对一的。
我该怎么做才能为DataStoreProvider创建一个表,另一个列出DataStoreProvider的Id - NativeType列和ODBCType枚举值?
这些是数据库表 -
DataStoreProvider
===============
1|d1
2|d2
nativeToODBC
===============
1|@NativeType(VARCHAR2,4000,0)|ODBCType.SQL_VARCHAR
1|@NativeType(CHAR,4000,0)|ODBCType.SQL_CHAR
提前致谢!