相关疑难解决方法(0)

JPA和Hibernate有什么区别?

我知道JPA 2是一个规范,Hibernate是ORM的工具.另外,我知道Hibernate比JPA 2有更多的功能.但从实际的角度来看,真正的区别是什么?

我有使用iBatis的经验,现在我正在尝试学习Hibernate或JPA2.我选了Pro JPA2书,它一直指的是"JPA提供者".例如:

如果您认为某个功能应该标准化,那么您应该说出来并向您的JPA提供商索取

这让我很困惑,所以我有几个问题:

  • 单独使用JPA2可以通过简单地注释我的POJO来从DB中获取数据
  • JPA2是否应该与"JPA Provider"一起使用,例如TopLink或Hibernate?如果是这样,那么使用JPA2 + Hibernate与单独使用JPA2相比有什么好处,或者与单独的Hibernate相比?
  • 你能推荐一本好的实用JPA2书吗?"Pro JPA2"似乎更像是JPA2上的圣经和参考(直到本书的后半部分才进入查询).有没有一本书对JPA2采取问题/解决方案?

java orm hibernate jpa java-ee

681
推荐指数
10
解决办法
49万
查看次数

添加spring boot jpa依赖项时,创建名为'entityManagerFactory'的bean时出错

尝试将JPA添加到Spring Boot程序时遇到问题.一切正常,直到我将下面的内容添加到我的pom.xml中(我还没有添加任何与JPA Hibernate相关的代码)

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

运行创建的jar文件时出现以下错误.用mvn clean包编译返回没有错误.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078) ~[spring-context-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.12.RELEASE.jar!/:4.3.12.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.8.RELEASE.jar!/:1.5.8.RELEASE]
at hello.App.main(App.java:19) [classes!/:0.1.0] …
Run Code Online (Sandbox Code Playgroud)

spring hibernate jpa maven spring-boot

15
推荐指数
1
解决办法
2万
查看次数

Spring Boot - repository字段需要一个名为'entityManagerFactory'的bean,找不到它

我正在开发Spring Boot应用程序,并在启动服务器时遇到此错误.我不确定我是否错误地定义了任何注释或缺少任何依赖项.任何帮助,将不胜感激.

主要课程:

@SpringBootApplication
public class FantasyManagerApplication {

    public static void main(String[] args) {
        SpringApplication.run(FantasyManagerApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

LeagueService.java:

@Service
public class LeagueService {

    @Autowired
    private LeagueRepository leagueRepository;
    @Autowired
    private PlayerRepository playerRepository;
    @Autowired
    private TeamRepository teamRepository;

    /**
     * Returns a list of all the leagues in the database 
     * @return List<League>
     */
    public List<League> getAllLeagues(){
        List<League> leagues = new ArrayList<>();
        leagueRepository.findAll()
        .forEach(leagues::add);
        return leagues;
    }

    /**
     * Find details for a particular League
     * @param leagueId
     * @return League
     */ …
Run Code Online (Sandbox Code Playgroud)

java sql rest spring-mvc spring-boot

12
推荐指数
2
解决办法
4万
查看次数

SSLHandShakeException没有适当的协议

我最近在我的网站上添加了SSL,可以通过https访问.现在,当我的java应用程序尝试向我的网站发出请求并使用缓冲读取器从中读取它时,它会生成此堆栈跟踪

我没有使用自签名证书,证书来自Namecheap,他使用COMODO SSL作为CA来签署我的证书.即时通讯使用java 8

javax.net.ssl.SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
at sun.security.ssl.Handshaker.activate(Handshaker.java:503)
at sun.security.ssl.SSLSocketImpl.kickstartHandshake(SSLSocketImpl.java:1482)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1351)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:559)
Run Code Online (Sandbox Code Playgroud)

我的代码非常基本,只是尝试使用缓冲读取器在我的网站上阅读页面

 private void populateDataList() {
    try {
        URL url = new URL("https://myURL.com/Data/Data.txt");
        URLConnection con = url.openConnection();
        con.setRequestProperty("Connection", "close");
        con.setDoInput(true);
        con.setUseCaches(false);

        BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
        String line;
        int i = 0;
        while((line = in.readLine()) != null) {
            this.url.add(i, line);
            i++;
        }
    }   catch (Exception e) {
        e.printStackTrace();
    }

}
Run Code Online (Sandbox Code Playgroud)

我已经尝试将我的SSL证书添加到JVM的密钥库中,我甚至尝试使用此代码接受每个证书(这证明了我知道的SSL的目的)

 private …
Run Code Online (Sandbox Code Playgroud)

java ssl bufferedreader

8
推荐指数
7
解决办法
3万
查看次数

使用在类路径资源中定义的名称“entityManagerFactory”创建 bean 时出错(调用 init 方法失败)

当我尝试使用 hibernate 和 MySql 运行我的 spring-boot 项目时,出现以下错误。

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-07-10 15:15:32.474 ERROR 12112 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.sliit.af.model.Course
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
    at …
Run Code Online (Sandbox Code Playgroud)

java mysql hibernate jpa spring-boot

7
推荐指数
3
解决办法
5万
查看次数

使用 PostgreSQL 和 Spring Boot 项目创建名称为entityManagerFactory的bean时出错

当我尝试编译项目时出现错误

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-02-11 15:21:24.256 ERROR 14192 --- [           main] o.s.boot.SpringApplication               : Application run failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactory' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'entityManagerFactoryBuilder' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Unsatisfied dependency expressed through method 'entityManagerFactoryBuilder' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa spring-boot

3
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×5

hibernate ×4

jpa ×4

spring-boot ×4

bufferedreader ×1

java-ee ×1

maven ×1

mysql ×1

orm ×1

rest ×1

spring ×1

spring-mvc ×1

sql ×1

ssl ×1