1

我正在使用 Spring、MySQL 和 Hibernate 返回针对列“row_id”调整的超出范围值,并且我试图在我的数据库中插入一行,但出现以下错误:

Hibernate: insert into school_visit (borough, comments, date_of_visit, district, follow_up_action, meeting_schedule, met_with, nt_user, reaction_of_chapter, region, school, time_of_visit, time_stamp, topics_members, topics_speaker, type_of_visit, visitor_fname, visitor_id, visitor_lname) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2012-09-05 15:13:41,692 [http-8080-1] WARN  org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 22001
2012-09-05 15:13:41,692 [http-8080-1] ERROR org.hibernate.util.JDBCExceptionReporter - Data truncation: Out of range value adjusted for column 'row_id' at row 1

下面是我正在使用的模型,您可以看到 row_id 设置为 @GeneratedValue 那么为什么会出现此错误。

下面是我的模型:

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

@Entity
@Table(name = "school_visit")
public class VisitModel {

    public Long getRow_id() {
        return row_id;
    }

    public void setRow_id(Long row_id) {
        this.row_id = row_id;
    }

    public String getVisitor_fname() {
        return visitor_fname;
    }

    public void setVisitor_fname(String visitor_fname) {
        this.visitor_fname = visitor_fname;
    }

    public String getVisitor_lname() {
        return visitor_lname;
    }

    public void setVisitor_lname(String visitor_lname) {
        this.visitor_lname = visitor_lname;
    }

    public String getVisitor_id() {
        return visitor_id;
    }

    public void setVisitor_id(String visitor_id) {
        this.visitor_id = visitor_id;
    }

    public String getType_of_visit() {
        return type_of_visit ;
    }

    public void setType_of_visit(String type_of_visit) {
        this.type_of_visit = type_of_visit;
    }

    public String getDate_of_visit() {
        return date_of_visit;
    }

    public void setDate_of_visit(String date_of_visit) {
        this.date_of_visit = date_of_visit;
    }

    public String getBorough() {
        return borough;
    }

    public void setBorough(String borough) {
        this.borough = borough;
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

    public String getDistrict() {
        return district;
    }

    public void setDistrict(String district) {
        this.district = district;
    }

    public String getMet_with() {
        return met_with;
    }

    public void setMet_with(String met_with) {
        this.met_with = met_with;
    }

    public String getTime_of_visit() {
        return time_of_visit;
    }

    public void setTime_of_visit(String time_of_visit) {
        this.time_of_visit = time_of_visit;
    }

    public String getReaction_of_chapter() {
        return reaction_of_chapter;
    }

    public void setReaction_of_chapter(String reaction_of_chapter) {
        this.reaction_of_chapter = reaction_of_chapter;
    }

    public String getFollow_up_action() {
        return follow_up_action;
    }

    public void setFollow_up_action(String follow_up_action) {
        this.follow_up_action = follow_up_action;
    }

    public String getMeeting_schedule() {
        return meeting_schedule;
    }

    public void setMeeting_schedule(String meeting_schedule) {
        this.meeting_schedule = meeting_schedule;
    }

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    public String getTopics_speaker() {
        return topics_speaker;
    }

    public void setTopics_speaker(String topics_speaker) {
        this.topics_speaker = topics_speaker;
    }

    public String getTopics_members() {
        return topics_members;
    }

    public void setTopics_members(String topics_members) {
        this.topics_members = topics_members;
    }

    public Date getTime_stamp() {
        return time_stamp;
    }

    public void setTime_stamp(Date time_stamp) {
        this.time_stamp = time_stamp;
    }

    public String getNt_user() {
        return nt_user;
    }

    public void setNt_user(String nt_user) {
        this.nt_user = nt_user;
    }

    public String getRegion() {
        return region;
    }

    public void setRegion(String region) {
        this.region = region;
    }

    @Id
    @GeneratedValue
    @Column(name = "row_id")
    private Long row_id;

    @Size(max = 50)
    @Column(name = "visitor_fname", nullable = false)
    private String visitor_fname;

    @Size(max = 50)
    @Column(name = "visitor_lname", nullable = false)
    private String visitor_lname;

    @Size(max = 5)
    @Column(name = "visitor_id", nullable = false)
    private String visitor_id;

    @Size(max = 25)
    @Column(name = "type_of_visit", nullable = false)
    private String type_of_visit;

    @Size(max = 45)
    @Column(name = "date_of_visit", nullable = false)
    private String date_of_visit;

    @Size(max = 1)
    @Column(name = "borough", nullable = false)
    private String borough;

    @Size(max = 3)
    @Column(name = "school", nullable = false)
    private String school;

    @Size(max = 3)
    @Column(name = "district", nullable = false)
    private String district;

    @Size(max = 200)
    @Column(name = "met_with", nullable = false)
    private String met_with;

    @Size(max = 50)
    @Column(name = "time_of_visit", nullable = false)
    private String time_of_visit;

    @Size(max = 50)
    @Column(name = "reaction_of_chapter", nullable = false)
    private String reaction_of_chapter;

    @Size(max = 50)
    @Column(name = "follow_up_action", nullable = false)
    private String follow_up_action;

    @Size(max = 30)
    @Column(name = "meeting_schedule", nullable = false)
    private String meeting_schedule;

    @Size(max = 2450)
    @Column(name = "comments", nullable = false)
    private String comments;

    @Size(max = 2450)
    @Column(name = "topics_speaker", nullable = false)
    private String topics_speaker;

    @Size(max = 2450)
    @Column(name = "topics_members", nullable = false)
    private String topics_members;

    @Column(name = "time_stamp", nullable = false)
    private Date time_stamp;

    @Size(max = 50)
    @Column(name = "nt_user", nullable = false)
    private String nt_user;

    @Size(max = 3)
    @Column(name = "region", nullable = false)
    private String region;

    @Override
    public String toString() {
        return "VisitModel [row_id=" + row_id + ", visitor_fname="
                + visitor_fname + ", visitor_lname=" + visitor_lname
                + ", visitor_id=" + visitor_id + ", type_of_visit="
                + type_of_visit + ", date_of_visit=" + date_of_visit
                + ", borough=" + borough + ", school=" + school + ", district="
                + district + ", met_with=" + met_with + ", time_of_visit="
                + time_of_visit + ", reaction_of_chapter="
                + reaction_of_chapter + ", follow_up_action="
                + follow_up_action + ", meeting_schedule=" + meeting_schedule
                + ", comments=" + comments + ", topics_speaker="
                + topics_speaker + ", topics_members=" + topics_members
                + ", time_stamp=" + time_stamp + ", nt_user=" + nt_user
                + ", region=" + region + ", getRow_id()=" + getRow_id()
                + ", getVisitor_fname()=" + getVisitor_fname()
                + ", getVisitor_lname()=" + getVisitor_lname()
                + ", getVisitor_id()=" + getVisitor_id()
                + ", getType_of_visit()=" + getType_of_visit()
                + ", getDate_of_visit()=" + getDate_of_visit()
                + ", getBorough()=" + getBorough() + ", getSchool()="
                + getSchool() + ", getDistrict()=" + getDistrict()
                + ", getMet_with()=" + getMet_with() + ", getTime_of_visit()="
                + getTime_of_visit() + ", getReaction_of_chapter()="
                + getReaction_of_chapter() + ", getFollow_up_action()="
                + getFollow_up_action() + ", getMeeting_schedule()="
                + getMeeting_schedule() + ", getComments()=" + getComments()
                + ", getTopics_speaker()=" + getTopics_speaker()
                + ", getTopics_members()=" + getTopics_members()
                + ", getTime_stamp()=" + getTime_stamp() + ", getNt_user()="
                + getNt_user() + ", getRegion()=" + getRegion()
                + ", getClass()=" + getClass() + ", hashCode()=" + hashCode()
                + ", toString()=" + super.toString() + "]";
    }



}

这是我的插入语句:

sessionFactory.getCurrentSession().saveOrUpdate(visit);

所以我不明白为什么我会收到这个错误

这是我的 jdbc.pro 文件:

database.driver=com.mysql.jdbc.Driver
database.url=jdbc:mysql://dvdbm01.dev/svr_dev
database.user=jxxxx
database.password=xxxx
ibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.show_sql=true

这是我的数据库 xml 文件:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:jdbc="http://www.springframework.org/schema/jdbc"

       xsi:schemaLocation="http://www.springframework.org/schema/beans 
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context 
                            http://www.springframework.org/schema/context/spring-context-3.0.xsd
                            http://www.springframework.org/schema/tx
                            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                            http://www.springframework.org/schema/jdbc
                            http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd">



  <context:property-placeholder location="classpath:jdbc.properties" />

  <context:component-scan base-package="org.uftwf" />

  <tx:annotation-driven transaction-manager="hibernateTransactionManager"/>

    <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${database.driver}" />
        <property name="url" value="${database.url}" />
        <property name="username" value="${database.user}" />
        <property name="password" value="${database.password}" />
    </bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="annotatedClasses">
            <list>
                <value>org.uftwf.schoolvisit.model.VisitModel</value>
                <value>org.uftwf.schoolvisit.model.NameID_lookupModel</value>
                <value>org.uftwf.schoolvisit.model.School_lookupModel</value>
            </list>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>             
            </props>
        </property>
    </bean>

    <bean id="hibernateTransactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
</beans>
4

2 回答 2

2

可能是您尝试设置的值对于签名字段类型而言太大。
为了了解更多有关此的信息,请参阅...
http://webomania.wordpress.com/2006/10/01/out-of-range-value-adjusted-for-column-error/
干杯!!!

于 2012-09-06T12:42:33.873 回答
0

试试这个

@GeneratedValue(strategy=GenerationType.IDENTITY)

另外,检查您是否使用了正确的 MySQL 方言。

于 2012-09-05T19:44:07.197 回答