2
I am new to the subject Hibernate, for the little I have learned, I believe I did everything right, ie, I lowered the dependencies, I wrote down the classes, etc. Below follows my class example:
package br.com.evolutionary.modelo;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Pokemon {
@Id
@GeneratedValue
private Long id;
@Column
private String nome;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
}
Now follow my persistence.xml file:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="evolutionary"
transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
<property name="hibernate.connection.url" value="jdbc:mysql://localhost:3306/evolutionary" />
<property name="hibernate.connection.driver" value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password" value="" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
My pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>br.com</groupId>
<artifactId>evolutionary</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.0.Final</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
Next, when starting Tomcat, entities are not created, I do not see Hibernate log. So my questions are:
You need to configure something in Tomcat?
The Hibernate is started in another way?
Somebody help me please?
Note: The above files were changed based on the answers already obtained and by questions.
Did you correctly annotate all the classes that will be persisted? ( Entity, Id, Collumn, etc.. )
– Sérgio Mucciaccia
Post the Log it generates, otherwise it is difficult to help you.
– Geferson
@Sérgiomucciaccia I will edit my question and add the code.
– Roknauta
@Geferson will edit the question and add the output.
– Roknauta
Class mapping is correct. the persistence file, leave it as update instead of create. Create deletes the bank every time it runs and creates again. update just updates, comments this generateDdl tag, the log I believe has more stuff, you posted what is in the log tab of Tomcat?
– Geferson
@Douglas Your problem has been solved?
– Matheus
@Matheus in part yes. I’ll make some more adjustments yet.
– Roknauta
@Douglas, I’ve tried to add your entities in tags
<class></class>
.?– Marcos Sousa
I just experienced the same problem. A possible solution is in the git repository: https://github.com/plinio352/WebHibernate.git
– Plinio PS