如何在运行时映射表?

时间:2015-06-16 03:33:56

标签: java hibernate postgresql mapping runtime

我有一张桌子:

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);)和所有工作:)

0 个答案:

没有答案