日期:2014-05-17 浏览次数:20675 次
Session session = HibernateSessionFactory.getSession(); Transaction tran = session.beginTransaction(); Speak s = (Speak)session.get(Speak.class, 1); System.out.println("at:"+s.getAttachmentFlag()); tran.commit(); session.close(); return "success";
<property name="attachmentFlag" type="java.lang.String"> <column name="attachment_flag" length="20"></column> </property>
-- Table "speak" DDL CREATE TABLE `speak` ( `speak_id` int(11) NOT NULL auto_increment, `user_id` int(11) default NULL, `content` mediumtext, `create_time` timestamp NULL default NULL on update CURRENT_TIMESTAMP, `last_comm_time` timestamp NULL default NULL COMMENT '后评论最时间', `cate_flag` varchar(50) default NULL COMMENT 'twitter,style,topic', `x_id` int(11) default NULL COMMENT '现表示的是forum的id', `attachment_flag` varchar(20) default '0' , `comment_sum` int(11) default '0' COMMENT '应相的speak被评论的次数', `love_sum` int(11) default '0' COMMENT '对应的speak被喜欢的次数', `forward_sum` int(11) default '0' COMMENT '对应的speak被转发的次数', PRIMARY KEY (`speak_id`), KEY `user_id` (`user_id`), KEY `love_sum` (`love_sum`), KEY `cate_flag` (`cate_flag`), KEY `attachment_flag` (`attachment_flag`), CONSTRAINT `speak_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `user` (`user_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=gbk;
package com.shaiyaya.dao; import java.util.Date; /** * Speak entity. * * @author MyEclipse Persistence Tools */ public class Speak implements java.io.Serializable { // Fields private Integer speakId; private User user; private String content; private Date createTime; private Date lastCommTime; private String cateFlag; private Integer XId; private String attachmentFlag; private Integer commentSum; private Integer loveSum; private Integer forwardSum; // Constructors /** default constructor */ public Speak() { } /** full constructor */ public Speak(User user, String content, Date createTime, Date lastCommTime, String cateFlag, Integer XId, String attachmentFlag, Integer commentSum, Integer loveSum, Integer forward