Java 休眠插入已写入的变量,不工作

Java 休眠插入已写入的变量,不工作,java,hibernate,Java,Hibernate,当我尝试用Hibernate插入我编写的字符串时,我遇到了一个问题。如果我直接在代码中插入它们,它们就会插入,但是如果我插入变量,它就不会插入。有什么问题吗 代码如下: public class M6Hibernate { static String nombre; static String codigo_proveedor; static int precio; static int codigo_prod; static int stock;

当我尝试用Hibernate插入我编写的字符串时,我遇到了一个问题。如果我直接在代码中插入它们,它们就会插入,但是如果我插入变量,它就不会插入。有什么问题吗

代码如下:

public class M6Hibernate {

    static String nombre;
    static String codigo_proveedor;
    static int precio;
    static int codigo_prod;
    static int stock;
    static String fecha ="22/01/2014";

    public static void main(String[] args) {

        InsertarRemesa();
    }

    private static void InsertarRemesa(){
        try{
         SessionFactory sesion = SessionFactoryUtil.getSessionFactory();

            Session session = sesion.openSession();       
            Transaction tx = session.beginTransaction();
            Scanner lector = new Scanner(System.in);

            Remesas re = new Remesas();

            System.out.println("Vamos a insertar una Remesa.");

            System.out.print("\nIntroduce Codigo_Prod: ");
            codigo_prod = lector.nextInt();
            re.setCodigoProd(codigo_prod);

            System.out.print("\nIntroduce nombre Producto: ");
            nombre = lector.next();
            re.setNombre(nombre);   

            System.out.print("\nIntroduce el Stock: ");
            stock= lector.nextInt();
            re.setStock(stock);

            System.out.print("\nIntroduce el Precio: ");
            precio= lector.nextInt();
            re.setPrecio(precio);

            re.setFechaCompra(fecha);

            System.out.print("\nIntroduce el Codigo de Proveedor: ");
            codigo_proveedor= lector.next();
            re.setCodigoProveedor(codigo_proveedor);

            session.save(re);
            tx.commit();
            session.close();

        }


    catch(Exception e){ 

         System.err.println(e.getMessage());
    }            

    }

    }
从Remesas代码映射:


请提供Remesas的映射。此外,您可能正在捕获异常并忽略它。要么不抓住它,要么报告它。也许你有个例外告诉你出了什么问题,我能怎么办?谢谢。不要捕获异常,如果在那一点上有任何错误,请告诉我们。我不知道为什么,但它不会捕获任何异常。
?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 27-feb-2014 23:07:14 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
    <class name="primero.Remesas" table="remesas" catalog="m6hibernate">
        <id name="codigoProd" type="int">
            <column name="codigo_prod" />
            <generator class="assigned" />
        </id>
        <property name="nombre" type="string">
            <column name="nombre" length="45" />
        </property>
        <property name="stock" type="java.lang.Integer">
            <column name="stock" />
        </property>
        <property name="fechaCompra" type="string">
            <column name="fecha_compra" length="45" />
        </property>
        <property name="precio" type="java.lang.Integer">
            <column name="precio" />
        </property>
        <property name="codigoProveedor" type="string">
            <column name="codigo_proveedor" length="45" />
        </property>
    </class>
</hibernate-mapping>