Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从Spring应用程序访问外部数据库_Spring_Jpa_Datasource - Fatal编程技术网

从Spring应用程序访问外部数据库

从Spring应用程序访问外部数据库,spring,jpa,datasource,Spring,Jpa,Datasource,我的工作区中有两个项目,projectA和projectB 在projectA中,我有一个bean,它使用JPA构建了一个数据库,并在构建时带有注释。让我们将此数据库命名为dbA 在projectB中,我需要访问读写dbA 这两个项目都是Spring项目 问题: projectB如何知道projectA中的bean?我可以从projectB使用JPA(Hibernate)访问dbA吗? 现在,我使用JDBC和显式SQL查询从projectB访问dbA。但是我需要entityManager.mer

我的工作区中有两个项目,projectA和projectB

在projectA中,我有一个bean,它使用JPA构建了一个数据库,并在构建时带有注释。让我们将此数据库命名为dbA

在projectB中,我需要访问读写dbA

这两个项目都是Spring项目

问题:

projectB如何知道projectA中的bean?我可以从projectB使用JPA(Hibernate)访问dbA吗? 现在,我使用JDBC和显式SQL查询从projectB访问dbA。但是我需要entityManager.merge entityManager.save等等。可能吗

  • projectB如何知道projectA中的bean
通过将projectA中的bean作为依赖项添加到projectB

  • 我可以从projectB使用JPA(Hibernate)访问dbA吗
是的,你可以

  • 现在,我使用JDBC和显式SQL查询从projectB访问dbA。但是我需要entityManager.merge entityManager.save等等。可能吗

是的,在您将与JPA相关的ocde添加到projectB或从projectA创建JPA bean的jar并将jar作为依赖项添加到projectB之后,这是可能的。

非常感谢。ant和BuildXML可以实现创建jar和添加依赖项吗?我如何才能实现JPA不从projectB中的jar构建一个新的数据库,并查看dbA?提前谢谢。@tuxi-是的,你可以用ant来建造那个罐子。表不是由JPA自动创建的,所以我不认为这是一个问题。很抱歉,仍然询问,但对于Spring JPA entityManager的使用,我必须添加@Entity注释,对吗?因此,在启动时,它会再次构建表。我应该在哪里定义不构建实体只访问persistence.xml或Spring的aplicationContext.xml上的外部数据库。非常感谢much@tuxiJPA不再构建表。但是,hibernate和ecplipselink等底层实现具有创建表的选项。根据您使用的实现,您可以禁用/启用它们