0

I need to know whether automatic table creation is possible using PostgreSQL instead of Derby.

The story: I successfully set up a NetBeans Java project with Hibernate and Derby. I have created JPA controller classes from my entity classes. To test the project I created JUnit test classes for those controller classes.

When running those test classes for the first time, the tables will be automatically created in Derby. After executing the test, I can see the tables in the database browser.

In the persistence.xml there's a line like this

<property name="hibernate.connection.url" value="jdbc:derby://localhost:1527/MySampleDb;create=true"/>

setting up the connection and indicating the tables to be created when needed (note the ";create=true" at the end of the line).

When using PostgreSQL instead of Derby. This doesn't work anymore. Adding ";create=true" breaks the code. Is this automatic table creation possible with PostgreSQL at all? Should I use a different persistence library other than Hibernate?

1 Answer 1

9

Yes. This is possible. You need to set the hibernate.hbm2ddl.auto propery to create

        <property name="hibernate.hbm2ddl.auto" value="create"/>
Sign up to request clarification or add additional context in comments.

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.