java - JPA新手无法与数据库交互

标签 java database orm jpa configuration

我不久前开始使用 JPA,我认为它很棒,因为它的注释使编程变得如此简单。但我仍然有很多疑问,这让我放慢了脚步(大多数时候与配置问题有关):

  1. 我想了解 OEPE(Oracle Enterprise Pack for Eclipse) 中的 derby DB(我使用它进行学习)与流行的 MySQL DB(www.mysql.com) 之间的区别。让我困惑的是嵌入式数据库和非嵌入式数据库有什么区别。什么更好,您有什么推荐?

  2. 第二个疑问是关于我无法使用我的 derby DB(非嵌入式模式)修复的某些配置问题,我已经提出了一个问题,但我无法修复它。问题是,当我尝试访问数据库的某些表(这些表存在于数据库中,它们是由 JPA 功能从实体生成表创建的)时,我收到 SQLSyntaxErrorException 说这些表不存在。我知道这是不可能的,因为在 Eclipses 剪贴簿中手动插入的相同查询可以正常工作。我知道这与某些配置问题有关,但我不知道它是什么。 如果有更多 JPA 经验的人可以帮助我,我会非常高兴。

我用于编程的工具是 eclipse + OEPE、Java EE 6 和 GlassfishV3.0

这是我的其他问题的链接,我在其中更详细地解释了该问题: SQLSyntaxErrorException: Table/View 'BUYER' does not exist. What is missing?

提前致谢。

最佳答案

关于问题1:

Derby/JavaDB 有两种操作模式(引用形式 JavaDB documentation ):

嵌入式

Refers to Derby being started by a simple single-user Java application. With this option Derby runs in the same Java virtual machine (JVM) as the application. Derby can be almost invisible to the end user because it is started and stopped by the application and often requires no administration. The Derby documentation often refers to this as the embedded configuration or embedded mode.

服务器(或基于服务器)

Refers to Derby being started by an application that provides multi-user connectivity to Derby databases across a network. With this option Derby runs in the Java virtual machine (JVM) that hosts the Server. Applications connect to the Server from different JVMs to access the database. The Derby Network Server is part of the Derby software distribution and provides this type of framework for Derby. Derby also works well with other, independently developed Server applications. The Derby documentation often refers to this as the Network Server configuration or client/server configuration.

根据我的经验,两种模式的主要区别在于,在嵌入式模式下,数据库是应用程序的一部分,并且只有一个用户可以连接到数据库。

在服务器模式下,数据库不是应用程序的一部分,运行在不同的 JVM 或另一台机器上,并以多用户/多连接模式运行。

关于JavaDB和MySQL的比较,我认为这取决于你的应用和功能需求。快速谷歌搜索显示了这个comparison of relational db systems (可以在 Apache Derby 的字母“A”下找到 Derby)。

关于java - JPA新手无法与数据库交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5517667/

相关文章:

java - 将 PBKDF2 盐重新用于 AES/GCM 作为 IV : dangerous?

java - 使用 jackson 对具有抽象字段的对象进行序列化和反序列化

java - 使用maven问题在tomcat上部署war文件

mysql - 根据月份和日期从数据库中获取最新记录

java - 我可以在 JPA 中查询对象吗

java - 如何快速制作Java代码原型(prototype)?

java - 如何用neo4j计算共同好友?

c# - 安装后设置服务依赖

orm - ColdFusion ORM : Can I specify init arguments to be passed to related entities when loaded?

java - 为什么 JPA 实体类及其方法不能声明为 final?