名称终被备注代替 2015-06-17 02:34 采纳率: 0%
浏览 1695

hibernate3.0升级到4.2后Configuration.addClass无法加载

最近公司准备重新使用ssh,在之前有的项目上升级ssh版本,spring和struts都升级好了,现在在升级hibernate到最新版的时候遇到了问题,原本Configuration.addClass可以加载对应信息,然后用Configuration.getClassMapping获取加载的信息,但现在hibernate4.2后我试了很久都加载不了,请问是什么问题?下面是样例
import java.util.Date;

import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.PersistentClass;

public class testHibernater {
public static void main(String[] args){
TsCacheTablesInfo tsc=new TsCacheTablesInfo("ts_ccc", 10, new Date());
Configuration hibernateConf = new Configuration();
hibernateConf.addClass(tsc.getClass());
PersistentClass pc = hibernateConf.getClassMapping(tsc.getClass().getName());
System.out.println(pc);
}
}

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">




















package cn.com.jandar.oasis.evolution1.db.orm;

import java.util.Date;

/**

  • TsCacheTablesInfo entity.
  • @author MyEclipse Persistence Tools */

@SuppressWarnings("unchecked")
public class TsCacheTablesInfo implements java.io.Serializable {

// Fields

private Integer id;
private String tableName;
private Integer tableCount;
private Date lastChangeDt;
private Short enabled;

// Constructors

/** default constructor */
public TsCacheTablesInfo() {
}

/** minimal constructor */
public TsCacheTablesInfo(String tableName, Integer tableCount,
        Date lastChangeDt) {
    this.tableName = tableName;
    this.tableCount = tableCount;
    this.lastChangeDt = lastChangeDt;
}

/** full constructor */
public TsCacheTablesInfo(String tableName, Integer tableCount,
        Date lastChangeDt, Short enabled) {
    this.tableName = tableName;
    this.tableCount = tableCount;
    this.lastChangeDt = lastChangeDt;
    this.enabled = enabled;
}

// Property accessors

public Integer getId() {
    return this.id;
}

public void setId(Integer id) {
    this.id = id;
}

public String getTableName() {
    return this.tableName;
}

public void setTableName(String tableName) {
    this.tableName = tableName;
}

public Integer getTableCount() {
    return this.tableCount;
}

public void setTableCount(Integer tableCount) {
    this.tableCount = tableCount;
}

public Date getLastChangeDt() {
    return this.lastChangeDt;
}

public void setLastChangeDt(Date lastChangeDt) {
    this.lastChangeDt = lastChangeDt;
}

public Short getEnabled() {
    return this.enabled;
}

public void setEnabled(Short enabled) {
    this.enabled = enabled;
}

}

  • 写回答

2条回答 默认 最新

  • 名称终被备注代替 2015-06-17 08:48
    关注

    哈哈,自己解决了,hibernate4之后的版本Configuration类addClass后需要buildSessionFactory,不然不会生效

    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题