我正在研究使用Hibernate 4.1.9和JPA注释注释地图的不同方法.
如果我想存储一个Map,其中键是实体值的属性,则标记看起来像这样
@OneToMany(mappedBy = "deptById", targetEntity = com.demo.impls.Employee.class)
@MapKey(name = "entityId")
private Map<Long, Employee> employeesById;
Run Code Online (Sandbox Code Playgroud)
请注意,上面的标记不会创建连接表,但是Map会在运行时通过查询返回,因此Map是动态的,您不必在Java中将元素添加到地图中,以便查询返回它们.
现在我希望Map的内容能够反映应用程序添加到Map中的内容,而不是执行动态查询.
我想存储4种地图
private Map<String, String> map0;
private Map<String, Entity> map1;
private Map<Entity, String> map2;
private Map<Entity, Entity> map3;
Run Code Online (Sandbox Code Playgroud)
在这些情况下,密钥和价值之间没有任何关系,也没有与持有实体有任何关系.我必须能够指定连接表的名称以及键和值的列名.
我尝试了以下内容
@Entity
public class Department {
@ElementCollection
@CollectionTable(name = "TEST_MAP0")
@Column(name="value")
@MapKeyColumn(name="Key")
private Map<String, String> map0;
@ElementCollection(targetClass = com.demo.bb.impls.Employee.class)
@CollectionTable(name = "TEST_MAP1")
@Column(name="value")
@MapKeyColumn(name="Key")
private Map<String, Employee> map1;
@ElementCollection
@MapKeyClass(value = com.demo.bb.impls.Employee.class)
@CollectionTable(name = "TEST_MAP2")
@Column(name="value")
@MapKeyColumn(name="Key")
private Map<Employee, String> map2;
@ElementCollection(targetClass = com.demo.bb.impls.ParkingSpace.class) …Run Code Online (Sandbox Code Playgroud) 我正在运行一个 ChangeSet,需要检查前提条件中是否存在表。所以我的 ChangeSet 看起来像
<changeSet author="James" id="1548255530845-100">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="MY_NEW_TABLE" schemaName="${my_schema}"></tableExists>
</not>
</preConditions>
<createTable tableName="MY_NEW_TABLE">
<column name="IDX" type="${integer.type}">
<constraints nullable="false"/>
</column>
<column name="INTVAL" type="${integer.type}"/>
</createTable>
</changeSet>
Run Code Online (Sandbox Code Playgroud)
当我在大型数据库/模式上运行它时,它需要很长时间才能运行。
调试 Liquibase 内部的代码正在调用 SnapshotGeneratorFactory.has(DatabaseObject, Database)
public boolean has(DatabaseObject example, Database database) throws DatabaseException, InvalidExampleException {
List<Class<? extends DatabaseObject>> types = new ArrayList<Class<? extends DatabaseObject>>(getContainerTypes(example.getClass(), database));
types.add(example.getClass());
//workaround for common check for databasechangelog/lock table to not snapshot the whole database like we have to in order to handle case issues
if (example …Run Code Online (Sandbox Code Playgroud)