Quantcast
Channel: GUJ - Tópicos com a tag hibernate
Viewing all articles
Browse latest Browse all 759

ERROR: Duplicate entry '0' for key 'PRIMARY' , como consertar isso?

$
0
0

@Laio escreveu:

Oi pessoas, temnho esse problema aqui no netbenas, com aplicação javafx, no qual, quando vou fazer a persistencia de um objeto, usanodo Hibernate, se a lista fica vazia, ele opera normalmente, mas depois da primeira, ele retorna o seguinte erro:
ERROR: Duplicate entry ‘0’ for key ‘PRIMARY’
org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
INFO: HHH000010: On release of batch it still contained JDBC statements
THE ERROE IS ===>>>org.hibernate.exception.ConstraintViolationException: could not execute statement.

Como faco pra lidar com isso, parece que na parte de cadastro, ele sempre tenta começãr com id 0, mas não persiste porque já tem uma linha com id 0 no b. de dados, só não sei como resolver isso, Tem alguma coisa que possa fazer?

eis aqui o código:

public class Conectar {

public static SessionFactory Conexao() {
Configuration c = new Configuration();
c.configure();
SchemaExport sql = new SchemaExport©;
sql.create(true,false);
ServiceRegistry sr = new StandardServiceRegistryBuilder().applySettings(c.getProperties()).build();
return c.buildSessionFactory(sr);
}

public class AdicaoController implements Initializable {

/atributos omitidos/

 @FXML
private void criarEvento(ActionEvent event) {
    try{
       AgendaFactory ag = new AgendaFactory();
       Evento e = null;
       TempoFactory tf = new TempoFactory();
       Futuros f = ag.Futuro();
       LocalDate lc = calendar.getValue();
       Tempo t;
       EventosDao hibernate = new EventosDao();
       
       String mylocal = local.getText();
       String myname = nome.getText();
       String mydescricao  = descricao.getText();
       
           
    	int dia = lc.getDayOfMonth();//Dia em que comeca
		int mes  = lc.getMonthValue();//Mes
		int ano = lc.getYear();//Ano
		int hcomeco = horaInicial.getValue();//Hora em que come�a
		int mcomeco =  mimInicial.getValue();//minuto em que come�a
		int hfim = horaFinal.getValue();//Hora em que termina
		int mfim = minFinal.getValue();//minuto em que termina
		
          
         
t = tf.criartempo(dia, mes, ano, hcomeco, mcomeco, mfim, mfim);
//Aqui um tempo no construtor factory os atributos pedidos;
e = new Evento.BuilderEvento().setTempo(t).setNome(myname).
setLocal(mylocal).setDescricao(mydescricao).Builder();//EventoBuilder � criado
(f.adicionar(e))
  

if(hibernate.create(e)){
     ultimo.setText("SLAVO NO mYSQL"); 
}

    }catch(Exception e){
       ultimo.setText("coisa errada"); 
    }
    
}

@Entity
@Table(name = “Eventos”)
public class Evento implements Serializable{

@Id
private long id;

@GeneratedValue(strategy = GenerationType.SEQUENCE )
/atributos omitidos/

@ManyToOne
private Agenda agendados;

@OneToOne(cascade = CascadeType.ALL,
fetch = FetchType.LAZY,mappedBy = “fazerHoje”)

Entity
@Table(name = “tempodasCoisas”)
public class Tempo implements Serializable {

// @Embeddablle
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)

/atributos omitidos/

@OneToOne(cascade = CascadeType.ALL)
private Evento fazerHoje;

Mensagens: 1

Participantes: 1

Ler tópico completo


Viewing all articles
Browse latest Browse all 759

Trending Articles


Girasoles para colorear


mayabang Quotes, Torpe Quotes, tanga Quotes


Tagalog Quotes About Crush – Tagalog Love Quotes


OFW quotes : Pinoy Tagalog Quotes


Long Distance Relationship Tagalog Love Quotes


Tagalog Quotes To Move on and More Love Love Love Quotes


5 Tagalog Relationship Rules


Best Crush Tagalog Quotes And Sayings 2017


Re:Mutton Pies (lleechef)


FORECLOSURE OF REAL ESTATE MORTGAGE


Sapos para colorear


tagalog love Quotes – Tiwala Quotes


Break up Quotes Tagalog Love Quote – Broken Hearted Quotes Tagalog


Patama Quotes : Tagalog Inspirational Quotes


Pamatay na Banat and Mga Patama Love Quotes


Tagalog Long Distance Relationship Love Quotes


BARKADA TAGALOG QUOTES


“BAHAY KUBO HUGOT”


Vimeo 10.7.0 by Vimeo.com, Inc.


Vimeo 10.7.1 by Vimeo.com, Inc.



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>