Difference between configuring data source in persistence.xml and in spring configuration files

后端 未结 2 1521
青春惊慌失措
青春惊慌失措 2020-12-13 04:19

I\'ve seen (and done) data source configuration in two ways (the code below is just for demo):

1) configuration inside persistence units, like:

<         


        
2条回答
  •  不思量自难忘°
    2020-12-13 04:41

    It is strictly personal preference.

    My suggestion would be to use Spring's configuration if you are using Spring already. Its purpose is dependency injection and management so let it do its job with respect to your dependency on a database. If, however, you are not already using Spring, stick with the persistence configuration considering that this will keep your project simpler while still functional. I will suggest though that any project that needs Hibernate to interact with a database is probably big enough to condone using Spring within.

提交回复
热议问题