我有一张桌子:
CREATE TABLE airports (
id SERIAL PRIMARY KEY,
name VARCHAR2 NOT NULL,
);
有这个类用于映射:
@Entity(name = "AirportEntity")
@Table(name = "airports", schema = "public", catalog = "postgres")
public class AirportsEntity {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Basic
@Column(name = "name")
private String name;
/* getter and setter */
}
如何在运行时设置catalog = "postgres"
?我想要catalog = parameter
,其中parameter
设置为运行时。
PS。我在表格注释上删除了schema = "public", catalog = "postgres"
,并在运行时删除hibernate.cfg.xml
集<property name="hibernate.connection.url"></property>
,
(configuration.getProperties().setProperty("hibernate.connection.url", "jdbc:postgresql://" + ip + ":" + port + "/"+ catalog);
)和所有工作:)