API or code : Difference between Hibernate 3 and 4?

后端 未结 1 674
情歌与酒
情歌与酒 2021-02-06 06:54

I have pasted Hibernate 3 configuration file , SessionFactory class to configure this config.xml and a bean with JPA annotations. I want to know if I were using

1条回答
  •  死守一世寂寞
    2021-02-06 07:25

    hibernate.cfg.xml

    File hibernate.cfg.xml is fine. It may look confusing that version is still 3.0 in hibernate-configuration-3.0.dtd, but thats how it is. DTD was not updated. Maybe you want to use names names prefixed with hibernate instead, for example hibernate.show_sql instead of show_sql. Names of properties can be found from documentation. Usually DTD_location used is http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd (vs. ..sourceforge...), but both should work.

    Building session factory

    As you see from the API, buildSessionFactory is deprecated. This is how it is built in 4.x:

    Configuration conf = new Configuration();
    conf.configure();
    serviceRegistry = new ServiceRegistryBuilder().applySettings(conf.getProperties()).buildServiceRegistry();        
    sessionFactory = configuration.buildSessionFactory(serviceRegistry);
    

    In many places in documentation this is still not up to date.

    Annotating entities

    In general no changes are needed to your mappings in bean class. Reason is that you are using normal JPA mappings and also Hibernate 3 is implementation of what is described in JPA specification.

    0 讨论(0)
提交回复
热议问题