spring+hibernate mapping class without xml

前端 未结 4 1145
不知归路
不知归路 2021-02-03 10:58

in my applicationContext.xml, this is how I map xml to POJO. how to map directory to class file without required to create xml?



        
4条回答
  •  情书的邮戳
    2021-02-03 11:59

    Instead of using XML mapping files, you can use the Hibernate Annotations library which is based on Java 5 annotations.

    As usual, you'll need to declare your persistence classes in the Hibernate configuration file (typically hibernate.cfg.xml), though you use the element to declare your persistent classes:

        
          
            
            
          
        
    

    If you are using the Spring framework, you can set up an annotation-based Hibernate session factory using the AnnotationSessionFactoryBean class, as shown here:

      
      
       
         
       
       
         
           org.hibernate.dialect.DerbyDialect
           create
           ...
         
       
       
         
           com.mycompany.sample.domain.Order
           com.mycompany.sample.domain.LineItem
           ...
         
       
     
    

提交回复
热议问题