hibernate注解方式

原创 2017年01月03日 15:26:38

spring_hibernate.xml

<!-- spring和 Hibernate整合 --> 
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">  
        <property name="dataSource" ref="dataSource"></property>  
        <property name="hibernateProperties">
            <props>
                <prop key="dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="myeclipse.connection.profile">MyEclipse MySQL</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
            </props>
        </property>
         <!-- 注解写法 -->
         <property name="annotatedClasses" >
           <list>
             <value>com.ssh.entity.SimpleProfessional</value>
           </list>
        </property> 

    </bean>

SimpleProfessional实体类

package com.ssh.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

/**
 * Professional entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name="professional",catalog="oa")
public class SimpleProfessional implements java.io.Serializable {

    // Fields

    /**
     * 
     */
    private static final long serialVersionUID = 9008124251016810039L;
    private Integer professionalId;
    private String professionalName;
    private Date professionalDate;
    // Constructors

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

    public SimpleProfessional(Integer professionalId, String professionalName) {
        super();
        this.professionalId = professionalId;
        this.professionalName = professionalName;
    }

    /** full constructor */
    public SimpleProfessional(String professionalName, Date professionalDate) {
        this.professionalName = professionalName;
        this.professionalDate = professionalDate;
    }

    // Property accessors

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @GenericGenerator(name = "professionalGenerator", strategy = "native")
    @Column(name="professional_id")
    public Integer getProfessionalId() {
        return this.professionalId;
    }

    public void setProfessionalId(Integer professionalId) {
        this.professionalId = professionalId;
    }

    @Column(name="professional_name")
    public String getProfessionalName() {
        return this.professionalName;
    }

    public void setProfessionalName(String professionalName) {
        this.professionalName = professionalName;
    }

    @Column(name="professional_date",length=10)
    public Date getProfessionalDate() {
        return this.professionalDate;
    }

    public void setProfessionalDate(Date professionalDate) {
        this.professionalDate = professionalDate;
    }

    @Override
    public String toString() {
        return "Professional [professionalId=" + professionalId
                + ", professionalName=" + professionalName
                + ", professionalDate=" + professionalDate + "]";
    }

}
版权声明:本文为博主原创文章,未经博主允许不得转载。

hibernate笔记: 关于懒加载和load()方法

重点牢记   1.Load支持懒加载,get不支持懒加载。 2.lazy的生命周期与session相同,lazy加载必须依赖于session一直开启。 3.Hibernate lazy属性,在...

hibernate注解方式单向一对多关联

hibernate单向一对多关联: 与单向多对一关联不同的是,关系配置在一方,多方不需额外的配置。这里我使用一对多的关系 1.hibernate.cfg.xml配置文件: 与之前手动在数据库建表不...

Hibernate一对一主键关联(基于annotation注解方式)

标签: hibernate 主键 关联 映射 存储 级联 one-to-one 分类:hibernate3.3.2  hibernate中一对一的关联有两种方式:一种...

Hibernate注解方式、HQL查询

  • 2017年08月17日 16:39
  • 8.17MB
  • 下载

hibernate annotation注解方式来处理映射关系

@Entity @Table(name="Workers") public class Employee implements Serializable { private stat...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:hibernate注解方式
举报原因:
原因补充:

(最多只允许输入30个字)