简体   繁体   中英

how can I create a table from a database row?

使用Hibernate命令,可以从行结果创建表吗?

CREATE TABLE new_table AS (SELECT * FROM old_table);

You are looking to create a materialized view, like so:

CREATE MATERIALIZED VIEW new_table AS SELECT * FROM old_table;

Source

2 ways to do it.

1)Creating table will require to link source base POJO(old table) into new POJO(new table) (with settrs and getters)

2)Create new table entity (with @Table ) and use native sql query to copy data

  .createNativeQuery( "INSERT INTO new_table SELECT * FROM old_table" )
  .executeUpdate();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM