Galera, tenho um dúvida sobre um exercício que foi passado na facul recentemente. Tenho que mapear classes com JPA, Hibernate e estou com um pouco de dificuldade na parte de mapear os relacionamentos dessas classes.
O problema é o seguinte, o exercício é sobre um Jogo de Futebol onde temos as classes Jogador, Time, Técnico, Juiz, Jogo.
No relacionamento ficaria Jogador possui um Time e o Time possui vários Jogadores. Até ai tudo bem!
Como mapiei este exemplo, e gostaria que vocês me ajudassem porque não estou conseguindo gerar o meu DB com esse mapeamento.
Aqui é a classe Jogador onde referencio o Time dele.
@ManyToOne(fetch = FetchType.EAGER) @JoinColumn(name="time_Cod", insertable=true,updatable=true) @Fetch(FetchMode.JOIN) @Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE) private Time time;
E meu Time que contém vários Jogadores.
@OneToMany(mappedBy="Time",fetch = FetchType.LAZY) @Cascade(CascadeType.ALL) private ArrayList<Jogador> jogador;
Há outros relacionamentos, mas, se eu botar aqui vocês acabariam fazendo minha atividade kkkk então só essa pequena ajuda já seria maravilhosa.
Se caso precisarem de mais informações, por favor me digam, e obrigado desde já!
EDIT- 1
Erro: set 06, 2016 12:45:00 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
set 06, 2016 12:45:00 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
set 06, 2016 12:45:00 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
set 06, 2016 12:45:00 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
name: conexaoDB
...]
set 06, 2016 12:45:00 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.8.Final}
set 06, 2016 12:45:00 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
set 06, 2016 12:45:00 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
set 06, 2016 12:45:00 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
set 06, 2016 12:45:00 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
set 06, 2016 12:45:00 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/db_testeAtvdAp02]
set 06, 2016 12:45:00 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=root, password=****}
set 06, 2016 12:45:00 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
set 06, 2016 12:45:00 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
set 06, 2016 12:45:01 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQL5InnoDBDialect
Erro no cadastro: [PersistenceUnit: conexaoDB] Unable to build Hibernate SessionFactory
EDIT 2- Arquivo de Persintencia:
<persistence version="2.0"
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/persistence_2_0.xsd">
<persistence-unit name="conexaoDB" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.hbm2ddl.auto" value="update" />
<property name="hibernate.show_sql" value="true" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name = "javax.persistence.jdbc.user" value="root" />
<property name = "javax.persistence.jdbc.password" value="" />
<property name = "javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/db_testeAtvdAp02" />
</properties>
</persistence-unit>
EDIT 3 - Código
public static void main(String[] args) {
try {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("conexaoDB");
factory.close();
System.out.println("Gerado");
} catch (Exception e) {
System.out.println("Não Gerado: "+e.getMessage());
}
}
mappedBy="Time"
paramappedBy="time"
persistence.xml
) e o código da fábrica de conexão @user54273persistence.xml
falta vc adicionar suas entidades nas tags<class> </class>
(Jogador, Time, Técnico, Juiz, Jogo) as que contem em seu código. não entendi por que vc declara usa fábrica em um métodomain
, mas vc não tem que fecha-lo! apague:factory.close();
e modifique<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
por<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
nopersistence.xml