名称终被备注代替 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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?