具有@Lob String字段的单边ManyToOne子级返回空父级

时间:2018-07-02 08:44:12

标签: java mysql spring hibernate

Link to 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生态系统上的休眠配置:

@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;
}

0 个答案:

没有答案