3

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?

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

2

Try this:

session.createSQLQuery(query).executeUpdate();

another possibility would be:

createStatement().execute(someddl);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.