Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Hibernate create tables in the database automatically

Tags:

java

hibernate

Upon reading this (archived) tutorial, they have not mentioned anything over creating tables in the DB. Does the Hibernate handle it automatically by creating tables and fields once i specify them.

Here is my beans configuration.

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:p="http://www.springframework.org/schema/p"     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">      <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" />          <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">         <property name="driverClassName" value="com.mysql.jdbc.Driver"/>         <property name="url" value="jdbc:mysql://127.0.0.1:3306/spring"/>         <property name="username" value="monwwty"/>         <property name="password" value="www"/>     </bean>          <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">         <property name="dataSource" ref="myDataSource" />         <property name="annotatedClasses">             <list>                 <value>uk.co.vinoth.spring.domain.User</value>             </list>         </property>         <property name="hibernateProperties">             <props>                 <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>                 <prop key="hibernate.show_sql">true</prop>                 <prop key="hibernate.hbm2ddl.auto">create</prop>             </props>         </property>     </bean>          <bean id="myUserDAO" class="uk.co.vinoth.spring.dao.UserDAOImpl">         <property name="sessionFactory" ref="mySessionFactory"/>     </bean>          <bean name="/user/*.htm" class="uk.co.vinoth.spring.web.UserController" >         <property name="userDAO" ref="myUserDAO" />     </bean>      </beans> 
like image 793
theJava Avatar asked Dec 22 '10 07:12

theJava


People also ask

How many tables created many to many in Hibernate?

Bookmark this question.


1 Answers

your hibernate.hbm2ddl.auto setting should be defining that the database is created (options are validate, create, update or create-drop)

like image 185
David O'Meara Avatar answered Oct 19 '22 16:10

David O'Meara