2
I’m having errors due to my mapping to my java program, I’m still starting to mess with Annotation (I ask you to forgive possible stupid xD errors). Error must be on @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 several players, but each player belongs to only one account. In my BD I created a foreign key called ID_CONTA in the PLAYER table, to receive the ACCOUNT ID.
Would someone explain to me how I should correct that mistake?
Error:
INFO: HHH000400: Using dialect: org.hibernate.dialect.Mysqldialect nov 18, 2016 3:43:05 pm org.hibernate.engine.jdbc.env.internal.Lobcreatorbuilderimpl useContextualLobCreation INFO: 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.player 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
Classe Conta:
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
}
Hello, I’ll take a look at this material, but at first these changes didn’t work.
– Guilherme Souza