Hibernate configuration - session factory scanning?

前端 未结 5 1053
粉色の甜心
粉色の甜心 2020-12-22 01:06

We have this hibernate.cfg.xml file. Is there a way to tell Hibernate to just scan a directory instead of having to add an entry here for each class?



        
5条回答
  •  萌比男神i
    2020-12-22 01:39

    I was looking for a similar solution and found the answer from another question here. You should be using spring to make that work.

    1. Create a class EntityScannerSessionFactoryBean extending AnnotationSessionFactoryBean
    2. Copy the code from the link(Its a great answer make sure you read it). to your new class.
    3. Add the below to map that class as sessionFactory in your application context.

      bean id="sessionFactory" class="com.foo.EntityScannerSessionFactoryBean">

提交回复
热议问题