hibernate注解方式

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 + "]";
    }

}
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gates0087/article/details/53994859
个人分类: hibernate
上一篇StringMVC下json传值问题
下一篇hibernate缓存机制
想对作者说点什么? 我来说一句

Hibernate注解、注释大全

2011年06月10日 35KB 下载

没有更多推荐了,返回首页

关闭
关闭