关于hibernate的问题formula属性
实例类 News
package lee;
public class News
{
//消息类的标识属性
private int id;
//消息标题
private String title;
//消息内容
private String content;
//消息全部内容,由系统根据公式生成
private String fullContent;
//构造器
public News()
{
}
public News(int id , String title , String content
, String fullContent)
{
this.id = id;
this.title = title;
this.content = content;
this.fullContent = fullContent;
}
public void setId(int id)
{
this.id = id;
}
public int getId()
{
return this.id;
}
public void setTitle(String title)
{
this.title = title;
}
public String getTitle()
{
return this.title;
}
public void setContent(String content)
{
this.content = content;
}
public String getContent()
{
return this.content;
}
public void setFullContent(String fullContent)
{
this.fullContent = fullContent;
}
public String getFullContent()
{
return this.fullContent;
}
}
------------------------------------------------
测试类 NewsManager
package lee;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class NewsManager
{
public static void main(String[] args) throws Exception
{
//实例化Configuration,这行代码默认加载hibernate.cfg.xml文件
Configuration conf = new Configuration().configure();
//以Configuration创建SessionFactory
SessionFactory sf = conf.buildSessionFactory();
//实例化Session
Session sess = sf.openSession();
//开始事务
Transaction tx = sess.beginTransaction();
//创建消息实例
News n = new News();
//设置消息标题和消息内容
n.setTitle("疯狂Java联盟成立了");
n.setContent("疯狂Java联盟成立了,"
+ "网站地址http://www.crazyjava.org");
//保存消息
sess.save(n);
News n2 = (News)sess.get(News.class , 1);
//输出fullContent属性值
System.out.println(n2.getFullContent());
//提交事务
tx.commit();
//关闭Session
sess.close();
}
}
-------------------------------------
实体类映射文件News.hbm.xml
<?xml version="1.0" encoding="gb2312"?>
<!-- 指定Hiberante3映射文件的DTD信息 -->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--上面四行对所有的hibernate映射文件都相同 -->
<!-- hibernate-mapping是映射文件的根元素 -->
<hibernate-mapping package="lee">
<!-- 每个class元素对应一个持久化对象 -->
<class name="News" table="news_table_formula">
<!-- id元素定义持久化类的标识属性 -->
<id name="id">
<generator class="identity"/>
</id>
<!-- property元素定义常规属性 -->
<property name="title" not-null="true"/>
<property name="content"/>
<!-- 通过formula指定该属性值没有对应的实际数据列
该属性值将由系统根据表达式来生成-->
<property name="fullContent"
formula="(insert into news_table_formula (fullContent) value ('zyw'))"/>
</class>
</hibernate-mapping>
-------------------------------------------------
数据库配置文件hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate_base</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<!-- 指定连接池最大连接数 -->
<property name="hibernate.c3p0.max_size">20</property>
<!-- 指定连接池最小连接数 -->
<property name="hibernate.c3p0.min_size">1</property>
<!-- 指定连接池里连接的超时时长 -->
<property name="hibernate.c3p0.timeout">5000</property>
<!-- 指定连接池里最大缓存多少个Statement对象 -->
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
<property name="hibernate.c3p0.acquire_increment">2</property>
<property name="hibernate.c3p0.validate">true</property>
<!-- 指定数据库方言 -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- 根据需要自动创建数据表 -->
<property name="hbm2ddl.auto">create</property>
<!-- 显示Hibernate持久化操作所生成的SQL -->
<property name="show_sql">true</property>
<!-- 将SQL脚本进行格式化后再输出 -->
<property name="hibernate.format_sql">true</property>
<!-- 罗列所有映像文件 -->
<mapping resource="lee/News.hbm.xml"/>
</session-factory>
</hibernate-configuration>
---------------------------------------------------------------
代码都操书上答案的,可是运行时候查不出FullContent,而且设置formula了就生成不了FullContent字段,这是怎么回事啊