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