Execute a Create Table Query through the JPA EntityManager

后端 未结 2 858
失恋的感觉
失恋的感觉 2020-12-19 04:13

I need to create a new Table in a Database I access through a JPA EntityManager. Do JPA NativeQueries support Queries other than \"Select\" or \"Update\"? Or is there anothe

2条回答
  •  盖世英雄少女心
    2020-12-19 04:52

    JPA (at least Hibernate) can let you execute DDL statements directly using createNativeQuery() and executeUpdate() as follows:

    EntityManager em = ...;
    em.createNativeQuery("CREATE TABLE FOO (FOO_ID NUMBER)").executeUpdate();
    em.createNativeQuery("DROP TABLE FOO").executeUpdate();
    

    It's not ideal, but you can do it.

提交回复
热议问题