【hibernate】实体类创建的两种方式

1.在bo中这种方式
  @Entity
  @Table(name = "INTERFACE_APP")
类继承 implements java.io.Serializable
主键get方法前写:
    @GenericGenerator(name = "generator", strategy = "uuid.hex")
    @Id
    @GeneratedValue(generator = "generator")
    @Column(name = "user_id", unique = true, nullable = false, length = 32)
其他列get方法前写:
@Column(name = "CURRENT_LOGON_DATE", length = 3594)
如果是日期类型,没有长度

然后在hibernate.cfg.xml中配置
<hibernate-configuration>
 <session-factory>
  <mapping class="com.wondersgroup.sabic.gircs.interfaceinfo.bo.InterfaceApp" />
 </session-factory>
</hibernate-configuration>


2.首先创建一个类
public class MacroCollectRpt

然后写一个MacroCollectRpt.hbm.xml

<hibernate-mapping package="com.tmk.macro.model">
 <class name="MacroCollectRpt" table="MACRO_COLLECT_RPT">
  <id
   column="MACRO_COLLECT_RPT_ID"
   name="id"
   type="integer"
  >
  <generator class="com.wonders.gmis.common.id.IntegerIdGenerator">
   <param name="idName">MACRO_COLLECT_RPT_ID</param>
  </generator>
  </id>
  <property
   column="MONTH"
   length="7"
   name="month"
   not-null="true"
   type="date"
   />

 </class>
</hibernate-mapping>

本文出自 “HAPPY_CANDY” 博客,谢绝转载!

你可能感兴趣的:(BO,Hibernate,实体类)