简体   繁体   中英

Data truncation: Data too long for column 'xxx' at row x (boolean)

I am using hibernate mapping one to many to complete my task. But when I ran the project, it ran into a problem: "Data truncation: Data too long for column 'tinhTrang' at row 1". I can't get the point why I got this. I searched but I couldn't find any problem with boolean like me. Please help me. Thank everyone

.package com.javapoint;
import javax.persistence.*;  

@Entity  
@Table(name="DH")  
public class DonHang { 

@Id  
@GeneratedValue(strategy=GenerationType.TABLE)  
private int soDH;    
private int maKH;  
private double triGia;
@Column(nullable = false, columnDefinition = "TINYINT(4)")
private boolean tinhTrang;

public int getsoDH() 
{  
    return soDH;  
}  
public void setsoDH(int soDH) 
{  
    this.soDH = soDH;  
}  
public int getmaKH() 
{  
    return maKH;  
}  
public void setmaKH(int maKH) 
{  
    this.maKH = maKH;  
}  
public double gettriGia() 
{  
    return triGia;  
}  
public void settriGia(double triGia) 
{  
    this.triGia = triGia;  
}      
public boolean gettinhTrang()
{
    return tinhTrang;
}
public void settinhTrang(boolean tinhTrang)
{
    this.tinhTrang = tinhTrang;
}

}
Here is the error message:

Caused by: org.hibernate.exception.DataException: could not execute statement at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:52) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:113) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:99) at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:178) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3171) at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3686) at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.882 13246945888:90) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:478) at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:356) at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39) at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1454)... 9 more

Caused by: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Data too long for column 'tinhTrang' at row 1 at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:104) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:974) at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1113) at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdateInternal(ClientPreparedStatement.java:1061) at com.mysql.cj.jdbc.ClientPreparedStatement.executeLargeUpdate(ClientPreparedStatement.java:1381) at com.mysql.cj.jdbc.ClientPreparedStatement.executeUpdate(ClientPreparedStatement.java:1046) at org.8839 8379930688.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:175)... 17 more

The error originates from the MySQL server. You are trying to put a too big value into one of the columns.

You should check what value you are trying to add to the column and change the type for the column to something bigger.

For a better answer you need to supply more information on what data you are trying to add to each column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM