Good afternoon,
I'm trying to create the tables automatically, being that I think I should be missing something.
Can anyone help me?
this is my line of code
Cargo.java
package br.com.teste;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table
public class Cargo implements Serializable {
private int id;
private String descricao;
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
Official.java
package br.com.teste;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table
public class Funcionario {
private int id;
private String nome;
private String email;
private Cargo cargo = new Cargo();
public Cargo getCargo() {
return cargo;
}
public void setCargo(Cargo cargo) {
this.cargo = cargo;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Id
@GeneratedValue
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
}
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql:/localhost/teste</property>
<property name="hibernate.connection.username">root</property>
<property name="connection.password">123</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect </property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<mapping class="br.com.teste.Cargo"/>
<mapping class="br.com.teste.Funcionario"/>
</session-factory>
</hibernate-configuration>
console (logs)
Ago 11, 2014 5:20:38 PM org.apache.catalina.core.AprLifecycleListener init
INFORMAÇÕES: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib
Ago 11, 2014 5:20:38 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
ADVERTÊNCIA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Projeto' did not find a matching property.
Ago 11, 2014 5:20:38 PM org.apache.coyote.AbstractProtocol init
INFORMAÇÕES: Initializing ProtocolHandler ["http-bio-8080"]
Ago 11, 2014 5:20:38 PM org.apache.coyote.AbstractProtocol init
INFORMAÇÕES: Initializing ProtocolHandler ["ajp-bio-8009"]
Ago 11, 2014 5:20:38 PM org.apache.catalina.startup.Catalina load
INFORMAÇÕES: Initialization processed in 587 ms
Ago 11, 2014 5:20:38 PM org.apache.catalina.core.StandardService startInternal
INFORMAÇÕES: Starting service Catalina
Ago 11, 2014 5:20:38 PM org.apache.catalina.core.StandardEngine startInternal
INFORMAÇÕES: Starting Servlet Engine: Apache Tomcat/7.0.55
Ago 11, 2014 5:20:40 PM org.apache.catalina.core.StandardContext addApplicationListener
INFORMAÇÕES: The listener "com.sun.faces.config.ConfigureListener" is already configured for this context. The duplicate definition has been ignored.
Ago 11, 2014 5:20:40 PM com.sun.faces.config.ConfigureListener contextInitialized
INFORMAÇÕES: Inicializando Mojarra 2.1.7 (SNAPSHOT 20120206) para o contexto '/Projeto'
Ago 11, 2014 5:20:40 PM com.sun.faces.spi.InjectionProviderFactory createInstance
INFORMAÇÕES: JSF1048: Anotações PostConstruct/PreDestroy presentes. Os métodos ManagedBeans marcados com essas anotações informarão as anotações processadas.
Ago 11, 2014 5:20:40 PM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler ["http-bio-8080"]
Ago 11, 2014 5:20:40 PM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler ["ajp-bio-8009"]
Ago 11, 2014 5:20:40 PM org.apache.catalina.startup.Catalina start