-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: java.sql.BatchUpdateException: Data truncation : Help me
PostPosted: Mon Apr 17, 2006 5:45 pm 
Newbie

Joined: Wed Apr 05, 2006 5:27 pm
Posts: 6
Location: SP - BR
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

version 3.2 cr1

Mapping documents:
Code:
@Entity
class Empresa {
    private Long id;
    private String nome;
    private Set<Pagamento> pagamentos;

    /* Method gets and sets hidden */

    @ManyToMany(cascade = CascadeType.PERSIST)
    @JoinTable( name = "empresapagamento",
            uniqueConstraints = @UniqueConstraint( columnNames = {"empresa_id", "pagamento_id" } ),
            joinColumns = @JoinColumn(name = "empresa_id", referencedColumnName = "id"),
            inverseJoinColumns = @JoinColumn(name = "pagamento_id", referencedColumnName = "id")
    )
    public Set<Pagamento> getPagamentos() {
        return pagamentos;
    }
    @Id @GeneratedValue
    public Long getId() {
        return id;
    }
}


Code:
@Entity
class Pagamento {
    private Long id;
    private String descricao;
    private Set<Empresa> empresas;
   
    /* Method gets and sets hidden */

    @ManyToMany
    public Set<Empresa> getEmpresas() {
        return empresas;
    }

    @Id @GeneratedValue
    public Long getId() {
        return id;
    }
}


Code:
@Entity
class EmpresaPagamento {
    private EmpresaPagamentoPK id;
   
    @Id
    public EmpresaPagamentoPK getId() {
        return id;
    }
    /* Method gets, sets, hashcode and equals hidden */

}



Code:
@Embeddable
class EmpresaPagamentoPK {
    private Empresa empresa;
    private Pagamento pagamento;
    /* Method gets, sets, hashcode and equals hidden */
}



Code between sessionFactory.openSession() and session.close():

Code:
        Session s = HibernateUtil.getSession();
        Transaction t = s.beginTransaction();
       
        Empresa e = (Empresa) s.get(Empresa.class, new Long(15));
        Pagamento p = (Pagamento) s.get(Pagamento.class, new Long(4));
        EmpresaPagamentoPK pk = new EmpresaPagamentoPK();
        pk.setEmpresa(e);
        pk.setPagamento(p);
        EmpresaPagamento ep = new EmpresaPagamento();
        ep.setId(pk);
        s.saveOrUpdate(ep);
       
        t.commit();
        s.close();


Full stack trace of any exception that occurs:

Code:
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:988)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:337)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at loja.util.Util.main(Util.java:74)
Caused by: java.sql.BatchUpdateException: Data truncation: Out of range value adjusted for column 'empresa' at row 1
   at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:647)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
   ... 8 more

Name and version of the database you are using:

MySQL 5.0.18

The generated SQL (show_sql=true):

Code:

Hibernate:
    select
        empresa0_.id as id2_0_,
        empresa0_.nome as nome2_0_,
        empresa0_.cnpjDig as cnpjDig2_0_,
        empresa0_.cnpjFil as cnpjFil2_0_,
        empresa0_.cnpjNum as cnpjNum2_0_,
        empresa0_.inscricaoEstadual as inscrica6_2_0_,
        empresa0_.nomeFantasia as nomeFant7_2_0_
    from
        Empresa empresa0_
    where
        empresa0_.id=?
Hibernate:
    select
        pagamento0_.id as id4_0_,
        pagamento0_.descricao as descricao4_0_,
        pagamento0_.dias as dias4_0_
    from
        Pagamento pagamento0_
    where
        pagamento0_.id=?
Hibernate:
    select
        empresapag_.empresa,
        empresapag_.pagamento
    from
        EmpresaPagamento empresapag_
    where
        empresapag_.empresa=?
        and empresapag_.pagamento=?
Hibernate:
    insert
    into
        EmpresaPagamento
        (empresa, pagamento)
    values
        (?, ?)


Debug level Hibernate log excerpt:

Code:
4136 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - Adding to batch
4136 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - Executing batch size: 1
4156 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
4156 [main] DEBUG org.hibernate.jdbc.AbstractBatcher  - closing statement
4166 [main] DEBUG org.hibernate.util.JDBCExceptionReporter  - Could not execute JDBC batch update [insert into EmpresaPagamento (empresa, pagamento) values (?, ?)]
java.sql.BatchUpdateException: Data truncation: Out of range value adjusted for column 'empresa' at row 1
   at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:647)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:988)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:337)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at loja.util.Util.main(Util.java:74)
4166 [main] WARN org.hibernate.util.JDBCExceptionReporter  - SQL Error: 0, SQLState: 01004
4166 [main] ERROR org.hibernate.util.JDBCExceptionReporter  - Data truncation: Out of range value adjusted for column 'empresa' at row 1
4166 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener  - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:988)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:337)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at loja.util.Util.main(Util.java:74)
Caused by: java.sql.BatchUpdateException: Data truncation: Out of range value adjusted for column 'empresa' at row 1
   at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:647)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
   ... 8 more
4166 [main] DEBUG org.hibernate.jdbc.ConnectionManager  - registering flush end

_________________
Márcio Alves Barroso


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 19, 2006 12:31 pm 
Newbie

Joined: Wed Apr 05, 2006 5:27 pm
Posts: 6
Location: SP - BR
Hi guys,

About my problem, I understood what happened.

When the hibernate try to persist the object in the data base :

Code:
<table name='EmpresaPagamento'>
empresa - Integer
pagamento - integer
</table>


It is trying to persist my object 'Empresa' and not 'Empresa.id'.

So, ERROR org.hibernate.util.JDBCExceptionReporter - Data truncation: Out of range value adjusted for column 'empresa' at row 1.

Now, I need to fix my mapping.

But I don't know how to do that.

_________________
Márcio Alves Barroso


Top
 Profile  
 
 Post subject: Big Problem
PostPosted: Thu Dec 28, 2006 12:29 pm 
Newbie

Joined: Thu Dec 28, 2006 12:24 pm
Posts: 5
Location: Brazil
hey on your code


Code:
@Embeddable
class EmpresaPagamentoPK {
    private Empresa empresa;
    private Pagamento pagamento;
    /* Method gets, sets, hashcode and equals hidden */
}


try to do this:

Code:
@Embeddable
class EmpresaPagamentoPK {
    @ManyToOne
    @JoinColumn( name = "empresa_id" )
    public Empresa empresa;
    @ManyToOne
    @JoinColumn( name = "pagamento_id" )
    public Pagamento pagamento;
}



i was with equals problem, then a still trying and i do work :)

valew cara foi foda arrumar isso, espero ter ajudado!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 10:01 pm 
Newbie

Joined: Wed Apr 05, 2006 5:27 pm
Posts: 6
Location: SP - BR
Valew Skull ...

Eu já havia resolvido este problema a algum tempo ... mas de qq forma valew pela atenção ...

grande abraço

_________________
Márcio Alves Barroso


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.