What jar should I include to use javax.persistence package in a hibernate based application?

后端 未结 7 1360
生来不讨喜
生来不讨喜 2020-12-29 01:20

Is it ok to take it from Glassfish project ( glassfish-persistence-api) or may be there is a Hibernate jar?

7条回答
  •  [愿得一人]
    2020-12-29 01:52

    In general, i agree with above answers that recommend to add maven dependency, but i prefer following solution.

    Add a dependency with API classes for full JavaEE profile:

    
        7.0
        5.1.3.Final
    
    
    
        
            javax
            javaee-api
            ${javaee-api.version}
            provided
        
    
    

    Also add dependency with particular JPA provider like antonycc suggested:

    
        org.hibernate
        hibernate-entitymanager
        ${hibernate-entitymanager.version}
    
    

    Note provided in API dependency section: this means that corresponding jar will not be exported into artifact's lib/, but will be provided by application server. Make sure your application server implements specified version of JavaEE API.

提交回复
热议问题