Best
Best

Reputation: 2318

Execute sql CREATE TABLE query in Hibernate

I need to dynamically create a table using a Java method and tranform all its rows into a list of Mapping class objects. The questions are..

Upvotes: 3

Views: 13586

Answers (2)

Chris
Chris

Reputation: 23171

You could just execute a native sql query: session.createSQLQuery("create table .....").executeUpdate(); where "session" is your Hibernate session.

If you already have the mapping files, though, you can just set the hibernate.hbm2ddl.auto property in your hibernate configuration to generate the schema based on the mapping files.

Upvotes: 5

dbrin
dbrin

Reputation: 15673

Try this:

session.createSQLQuery(query).executeUpdate();

another possibility would be:

createStatement().execute(someddl);

Upvotes: 2

Related Questions