manytoone子级带有@lob字符串字段,返回空父级

t2a7ltrp  于 2021-06-20  发布在  Mysql
关注(0)|答案(0)|浏览(232)

链接到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;
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题