hibernate 指定数据库用户(schema)访问

因为在项目中使用了第三方框架,而第三方框架使用了另一个数据库用户

而hibernate默认使用的是项目配置的schema

我们可以通过hibernate注解简单的配置实现这个要求,见如下代码

@Entity

@Table(name = "ACT_DE_MODEL", catalog = "flowable",schema="flowable")

@DynamicInsert(value = true)

@DynamicUpdate(value = true)

public class ActDeModel extends BaseEntity implements Comparable<ActDeModel> {

关键代码即为@table schema配置,查看源码有如下说明,因此我们修改此值即可。

    /** (Optional) The schema of the table.

     * <p> Defaults to the default schema for user.

     */

    String schema() default "";

Defaults to the default schema for user 这句话的 意思就是说默认schema默认使用了系统默认的schema,而默认的schema通常我们配置在项目的配置文件中

今天是国庆节:
祝福我伟大的祖国永远繁荣昌盛!


爆款云服务器s6 2核4G 低至0.46/天,具体规则查看活动详情Blog Img