I'm having errors due to my mapping to my program in java, I'm still starting to mess with annotation (please forgive possible stupid errors xD). The error should be in @ ManyToOne / OneToMany ...
I have two tables, ACCOUNT and PLAYER. After creating an account, the user can create one or more players, that is, an account can have multiple players, but each player belongs only to one account. In my DB I created a foreign key called ID_CONTA in the PLAYER table, to receive the ID of the ACCOUNT.
Would anyone know how to correct this error?
Error:
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect Nov 18, 2016 3:43:05 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl INFO: UseContextualLobCreation: HHH000423: Disabling Contextual LOB creation as JDBC driver reported JDBC version [3] less than 4 Exception in thread "main" javax.persistence.PersistenceException: Unable to build entity manager factory at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory (HibernatePersistenceProvider.java:66) at javax.persistence.Persistence.createEntityManagerFactory (Persistence.java:55) at javax.persistence.Persistence.createEntityManagerFactory (Persistence.java:39) at Test.main (Test.java:10) Caused by: org.hibernate.AnnotationException: Associations marked as mappedBy must not define database mappings like @JoinTable or @JoinColumn: Account at org.hibernate.cfg.annotations.CollectionBinder.bind (CollectionBinder.java:478) at org.hibernate.cfg.AnnotationBinder.processElementAnnotations (AnnotationBinder.java:2140) at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready (AnnotationBinder.java:911) at org.hibernate.cfg.AnnotationBinder.bindClass (AnnotationBinder.java:738) at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies (AnnotationMetadataSourceProcessorImpl.java:245) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess $ 1.processEntityHierarchies (MetadataBuildingProcess.java:222) at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete (MetadataBuildingProcess.java:265) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata (EntityManagerFactoryBuilderImpl.java:847) at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build (EntityManagerFactoryBuilderImpl.java:874) at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory (HibernatePersistenceProvider.java:58) ... 3 more
Account Class:
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
@Entity
public class Conta {
@Id @GeneratedValue
private int id;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "Jogador")
@JoinColumn(name="idConta")
private List <Jogador> jogador;
private String email;
private String senha;
private String nome;
//gets e sets
}
Player Class:
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
@Entity
public class Jogador {
@Id @GeneratedValue
private int id;
@JoinColumn(name="id_conta")
private int idConta;
private String nome;
private int lvl;
private int exp;
private int corrupcao;
private int ouro;
private int força;
@ManyToOne
private Conta conta;
//gets e sets
}