Reputation: 2318
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..
Is there a way to execute CREATE TABLE query dynamically?
I saw some examples using doInHibernate() but it didn't work when I tried it. Can I do this without the particular method?
Upvotes: 3
Views: 13617
Reputation: 23179
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
Reputation: 15673
Try this:
session.createSQLQuery(query).executeUpdate();
another possibility would be:
createStatement().execute(someddl);
Upvotes: 2