Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Hibernate抛出最大大小属性是强制异常_Java_Postgresql_Hibernate - Fatal编程技术网

Java Hibernate抛出最大大小属性是强制异常

Java Hibernate抛出最大大小属性是强制异常,java,postgresql,hibernate,Java,Postgresql,Hibernate,我刚刚开始尝试使用Hibernate创建PostgreSQL数据库,但不断遇到以下异常: org.hibernate.HibernateException: java.lang.IllegalArgumentException: max size attribute is mandatory 当我在试图构建会话工厂的线路上运行main方法时,就会发生这种情况,但我在网上的任何地方都找不到有关此异常的任何信息。我想知道有没有人知道是什么导致了这一切 主要类别: package com.packa

我刚刚开始尝试使用Hibernate创建PostgreSQL数据库,但不断遇到以下异常:

org.hibernate.HibernateException: java.lang.IllegalArgumentException: max size attribute is mandatory
当我在试图构建会话工厂的线路上运行main方法时,就会发生这种情况,但我在网上的任何地方都找不到有关此异常的任何信息。我想知道有没有人知道是什么导致了这一切

主要类别:

package com.package.ingestor;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateTest {

    public static void main(String[] args){
        Student user = new Student();
        user.setStudentId(1);
        user.setStudentName("Bri Guy");
        user.setStudentAge(32);

        SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
        Session session = sessionFactory.openSession();
        session.beginTransaction();
        session.save(user);
        session.getTransaction().commit();
    }
}
休眠对象:

package com.bossanova.ingestor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

@Entity
@Table(name = "student", uniqueConstraints={@UniqueConstraint(columnNames={"id"})})
public class Student {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", length=11, nullable=false, unique=true)
    private Integer studentId;

    @Column(name = "name", length=20, nullable=true)
    private String studentName;

    @Column(name="age", length=5, nullable=true)
    private Integer studentAge;

    public Student() { }

    public Student(Integer studId, String studName, Integer studAge) {
        this.studentId = studId;
        this.studentName = studName;
        this.studentAge = studAge;
    }

    public Integer getStudentId() {
        return studentId;
    }

    public void setStudentId(Integer studentId) {
        this.studentId = studentId;
    }

    public String getStudentName() {
        return studentName;
    }

    public void setStudentName(String studentName) {
        this.studentName = studentName;
    }

    public Integer getStudentAge() {
        return studentAge;
    }

    public void setStudentAge(Integer studentAge) {
        this.studentAge = studentAge;
    }

    @Override
    public String toString() {
        return "Student= Id: " + this.studentId + ", Name: " + this.studentName + ", Age: " + this.studentAge;
    }
}
配置文件:

<!DOCTYPE hibernate-configuration SYSTEM
        "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.driver_class">org.postgresql.Driver</property>
        <property name="connection.url">jdbc:postgresql://localhost:5433/hibernatedb</property>
        <property name="connection.username">postgres</property>
        <property name="connection.password">password</property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQL95Dialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.internal.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>
        <mapping class="com.bossanova.ingestor.Student"/>
    </session-factory>
</hibernate-configuration>

org.postgresql.Driver
jdbc:postgresql://localhost:5433/hibernatedb
博士后
密码
1.
org.hibernate.dialogue.postgresql95dialogue
线
org.hibernate.cache.internal.NoCacheProvider
真的
创造

通过将Maven依赖项从hibernate Agrol切换到hibernate core,我解决了这个问题

<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.4.0.Final</version>
</dependency>

org.hibernate
冬眠核心
5.4.0.1最终版本

如果您正在使用hibernate Agrol,请将pom添加到您的依赖项中