http://hi.baidu.com/lyq32/blog/item/1a1b3c1f53c068cda7866901.html
文档

解决方案 »

  1.   

    http://www2.matrix.org.cn/resource/article/2007-04-09/Hibernate+Annotations_62c034f4-e62a-11db-b1bd-fb5572962927.html
      

  2.   

    如果你在hibernate网站上下载了hibernate-annotations,比如hibernate-annotations-3.3.0.GA,那么在
    hibernate-annotations-3.3.0.GA\hibernate-annotations-3.3.0.GA\doc\reference\zh_cn\pdf下有一个中文的中文的annotation帮助文档1 applicationContext.xml中配置基于注释的sessionFactory
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.SQLServerDialect
    </prop>
    <prop key="hibernate.show_sql">true</prop>
    <prop key="hiberante.format_sql">true</prop>
    <!-- <prop key="hibernate.cache.provider_class">
    org.hibernate.cache.EhCacheProvider
    </prop> -->
    </props>
    </property>
    <property name="annotatedClasses">
    <list>
    <value>com.xxx.entity.User</value>
    <value>com.xxx.entity.Document</value>
    </list>
    </property>
    <property name="annotatedPackages">
    <list>
    <value>com.xxx.entity</value>
    </list>
    </property>
    </bean>
    2 实体类的一对多多对已关系的简单例子如下:
    @Entity
    @Table(name = "Users")
    public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String code;
    @OneToMany(mappedBy="author",cascade=CascadeType.ALL)
    private Collection<Document> documents;
    get/set......
    ......
    }@Entity
    @Table(name="Documents")
    public class Document {
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;
    private String caption;
    @ManyToOne
    @JoinColumn(name="author_id",referencedColumnName="id")
    private User author; 
    get/set......
    ......
    }