Using hbm2ddl with two entity managers in Hibernate

I try to split the database into two parts and wonder if there is a way in Hibernate to have two entity managers, but to specifically mark certain entities only so that one of the two entity managers picks them up.

// setup primary DB
Persistence.createEntityManagerFactory("default", paramsDefault.toTypedArray()))    

// setup audit DB
Persistence.createEntityManagerFactory("audit", paramsAudit.toTypedArray()))

In my configuration (this is only for dev, in production we will not use hbm2dll), I have a line:

<property name="hibernate.hbm2ddl.auto" value="update"/>

What objects will be executed?

Is there a way, for example, to force this object:

@Entity()
@Table(name = "accounts")
data class Account(

    @Column(nullable = false, unique = true)
    var username: String = "",

    @Column(nullable = false, unique = true)
    var email: String = "",

    ....

is available only when using the default object manager and not the audit entity manager?

In other words, how to prevent the creation of a table Accountin a database auditand an audit entity in a database default?

+4
source

Source: https://habr.com/ru/post/1688267/


All Articles