I have an application that uses Hibernate 4.1 and Spring 3.1.1. I am using Spring's HibernateJpaVendorAdapter and setting generateDdl to true to create the entities.
I just created a View and created an Entity to map to that View. The Entity for the view is annotated with @Entity, @Table(name="ViewName") and @Immutable. When I deploy the web app it automatically creates tables for all Entities which creates a table for the entity that is supposed to map to my View. I have to go in and manually drop that table and then create the view. While I could continue to do this I wanted to know if there was a way to specify to not create a table for that particular "View" Entity.
Of-course if you use it only for querying purpose then it should be fine.
Hibernate can create table, hibernate sequence and tables used for many-to-many mapping on your behalf but you have to explicitly configure it by calling setProperty("hibernate. hbm2ddl. auto", "create") of Configuration object.
A developer can have Hibernate create tables by adding the hbm2ddl. auto property and setting it to one of the following four values: validate. update.
Right-click the JPA project in the Project Explorer and select JPA Tools > Generate Entities from Tables. On the Select Tables page of the Generate Entities from Tables wizard, select your database connection and schema. To create a new database connection, click Add connection.
If you mark it as an entity then hibernate will always try to make the table if the hibernate.hbm2ddl.auto property is set to update, create-drop, or create. To stop this, get rid of this setting in your config file.
As Kevin pointed out these options are supposed to only be used during the developement phase or really bad things could happen to your prod db. Be sure to remove them before deploying there.
Check out the hibernate docs for more information
http://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/session-configuration.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With