I'm doing a project in eclipse with the framework spring using several technologies, mainly hibernate and jpa but I can not get the tables created in the database and I can not figure it out because I can not make the persistence of the objects if they do not exist. I'm working with maven and the truth is not if I'm missing some dependence or something else; and I am using a generic DAO model and also the annotations to map the classes to supposedly "create" the relationships for the tables. If anyone can tell me even if I have a ";" I would appreciate it.
this is the persistence file where I connect to the database
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence
http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
version="2.1">
<persistence-unit name="unidad">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>model.Usuario</class>
<class>model.Template</class>
<class>model.Publicacion</class>
<class>model.NotificacionCartelera</class>
<class>model.Media</class>
<class>model.Comentario</class>
<class>model.Cartelera</class>
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/grupo18"/>
<property name="hibernate.connection.username" value="root"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create"/>
</properties>
</persistence-unit>
</persistence>
this is the web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>Spring MVC</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springmvc-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
this is the context of the application xml
<?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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
<!-- Habilitamos configuración basada en anotaciones -->
<context:annotation-config />
<context:component-scan base-package="spring" />
<!--<context:component-scan base-package="ttps.daosjpa" /> -->
<!--<context:property-placeholder location="classpath:database.properties"
/> -->
<!-- DataSource -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="com.mysql.jdbc.Driver" />
<!-- <property name="driverClass" value="com.mysql.jdbc.Driver"/> sin usan
.properties -->
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/grupo18" />
<property name="user" value="root" />
<property name="minPoolSize" value="20" />
<property name="maxPoolSize" value="50" />
<property name="maxIdleTime" value="600" />
</bean>
<bean id="emf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="spring.model" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<!-- Manejador de Transacciones -->
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emf" />
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
this is an example of a class
package model;
import java.util.Collection;
import javax.persistence.*;
@Entity
@Table(name="cartelera")
public class Cartelera {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "id")
private Integer id;
private String tipo;
@ManyToMany
private Collection<Template> templates;
@OneToMany( mappedBy = "cartelera", cascade={CascadeType.REMOVE,CascadeType.REFRESH,CascadeType.MERGE})
private Collection<Publicacion> publicaciones;
@OneToMany(mappedBy="cartelera")
private Collection<NotificacionCartelera> notificacion;
private String descripcion;
@ManyToMany(mappedBy = "carteleras")
private Collection<Usuario> usuarios;
public Cartelera(String tipo, String descripcion) {
super();
this.tipo = tipo;
this.descripcion = descripcion;
}
public Cartelera(){
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTipo() {
return tipo;
}
public void setTipo(String tipo) {
this.tipo = tipo;
}
public String getDescripcion() {
return descripcion;
}
public void setDescripcion(String descripcion) {
this.descripcion = descripcion;
}
public Collection<Usuario> getUsuarios() {
return usuarios;
}
public void setAlumnos(Collection<Usuario> usuarios) {
this.usuarios = usuarios;
}
public Collection<Publicacion> getPublicaciones() {
return publicaciones;
}
public void setPublicaciones(Collection<Publicacion> publicaciones) {
this.publicaciones = publicaciones;
}
}