链接到github
父实体:
@Entity
@Table(name="paciente")
public class Paciente {
@Id
@Column(name="id", nullable=false, updatable=false, columnDefinition = "BINARY(16)")
private UUID id;
(...)
}
以及子实体:
@Entity
@Table(name = "avaliacao_clinica")
public class AvaliacaoClinica {
@Id
@Column(name="id", nullable=false, updatable=false, columnDefinition = "BINARY(16)")
private UUID id;
@ManyToOne(optional=false)
private Paciente paciente;
@Lob
private String obs;
(..)
}
这是一种单向的多对一关系。obs字段以前没有注解,但我需要它成为lob。进行更改后,对父级的引用总是空的。
这是spring生态系统上的hibernate配置:
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
String datasourceName = null;
String debug = null;
switch (ApplicationConstrains.ENVIROMENT) {
case DEVELOPMENT:
datasourceName = "jdbc/vet_dev";
debug = "true";
break;
case PRODUCTION:
datasourceName = "jdbc/vet_production";
debug = "false";
break;
}
Properties properties = new Properties();
properties.setProperty(Environment.HBM2DDL_AUTO, "update");
properties.setProperty(Environment.STORAGE_ENGINE, "innodb");
properties.setProperty(Environment.JDBC_TIME_ZONE, "UTC");
properties.setProperty(Environment.DIALECT, "org.hibernate.dialect.MySQL57Dialect");
properties.setProperty(Environment.SHOW_SQL, debug);
properties.setProperty(Environment.FORMAT_SQL, debug);
properties.setProperty(Environment.USE_SQL_COMMENTS, debug);
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
factoryBean.setDataSource(new JndiDataSourceLookup().getDataSource(datasourceName));
factoryBean.setJpaProperties(properties);
factoryBean.setPackagesToScan(Paciente.class.getPackage().getName());
return factoryBean;
}
@Bean
public PlatformTransactionManager transactionManager() {
JpaTransactionManager txManager = new JpaTransactionManager();
txManager.setValidateExistingTransaction(true);
txManager.setRollbackOnCommitFailure(true);
txManager.setEntityManagerFactory(entityManagerFactory().getObject());
return txManager;
}
暂无答案!
目前还没有任何答案,快来回答吧!