我研究了好久一直都不好用,网上查到的资料,要借助类增强器对二进制Class文件进行强化处理,这步说什么也不好使,我估计是hibernate版本的问题,例子中hibernate.jar 最好也给发一个 

解决方案 »

  1.   

    给一个例子,大字段其实就是JAVA里的String,因为在JAVA里字符串是没有长度限制的。
    static void insert() {
    Connection conn = null;
    PreparedStatement ps = null;
    Reader reader = null;
    try {
    conn = JdbcUtil.getConnection();
    String sql = "insert into clob_info(name,content) values (?,?)";
    ps = conn.prepareStatement(sql);
    ps.setString(1, "log4j.properties");
    File file = new File("src/log4j.properties");
    reader = new BufferedReader(new FileReader(file));
    // 注意,此处要将长度转化为int类型,
    // 因为在JDK1.6中虽然提供了long类型的长度参数,
    // 但在mysql 5的jar文件中还没有实现
    ps.setCharacterStream(2, reader, (int) file.length());
    // ps.setClob(2, reader, file.length());
    System.out.println("insert rows: " + ps.executeUpdate());
    reader.close(); } catch (Exception e) {
    e.printStackTrace();
    } finally {
    JdbcUtil.close(conn, ps);
    }
    }
    其中的content就是大字段类型。对应的表:
    create table clob_info(
    id int auto_increment,
    name varchar(20),
    content text,
    primary key (id));
    在MYSQL数据库中为text.
    而在HIBERNATE中,可 以通过组件映射将大文本放入指定的类中。并把其lazy属性设置为false
      

  2.   

    借助类增强器对二进制Class文件进行强化处理 我也搞了好久 搞不定 我先在都用 select new 构造函数(对象.属性1,对象.属性2,...) from 类名 as 对象 构造函数中没有大字段