在 Hibernate 中更改数据库时出现问题

发布于 2024-10-24 02:28:05 字数 2321 浏览 5 评论 0原文

我在休眠时遇到问题,并且不知道到底发生了什么,我正在工作这个项目,我使用以下设置连接到 Oracle 10g 数据库:

Host Name: localhost
port:1521
SID:orcl
user:anfxi
password:password

现在我在家里尝试使用同一个数据库远程,我通过 VPN 连接,数据库 IP 现在是 10.73.98.230 ,我导入了 WAR 并更改了我的设置 hibernate.cfg.xml from:

<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin://localhost:1521:orcl</property>
<property name="hibernate.connection.username">anfexi</property>
<property name="connection.password">password</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">validate</property>
<property name="current_session_context_class">thread</property>

to:

<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin://10.73.98.230:1521:orcl</property>
<property name="hibernate.connection.username">anfexi</property>
<property name="connection.password">password</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">validate</property>
<property name="current_session_context_class">thread</property>

但我不断收到此错误:

ERROR [main] (SchemaValidator.java:135) - could not get database metadata
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
localhost:1521:orcl

所以它似乎仍在使用 localhost 作为数据库地址,我清理了我的项目并重建,仍然没有运气,还有其他我可能会丢失的东西吗?休眠配置是否缓存在我必须删除的某些文件中?

编辑 对于它可能提供的服务,我可以使用 SQL Developer 进行连接,问题只是 hibernate 仍然使用旧的 localhost:1521:orcl 连接描述符。

感谢您的帮助!

i'm having a problem with hibernate and don't know exactly what's going on, i have this project at work where i connect to an Oracle 10g Database using the following settings:

Host Name: localhost
port:1521
SID:orcl
user:anfxi
password:password

Now i'm at home trying to work with the same database remotely, im connected via VPN and the database ip is now 10.73.98.230 , i imported my WAR and changed the settings in my
hibernate.cfg.xml from:

<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin://localhost:1521:orcl</property>
<property name="hibernate.connection.username">anfexi</property>
<property name="connection.password">password</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">validate</property>
<property name="current_session_context_class">thread</property>

to:

<property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
<property name="hibernate.connection.url">jdbc:oracle:thin://10.73.98.230:1521:orcl</property>
<property name="hibernate.connection.username">anfexi</property>
<property name="connection.password">password</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">validate</property>
<property name="current_session_context_class">thread</property>

but i keep getting this error:

ERROR [main] (SchemaValidator.java:135) - could not get database metadata
java.sql.SQLException: Listener refused the connection with the following error:
ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
The Connection descriptor used by the client was:
localhost:1521:orcl

so it seems to be still using localhost as the DB address, i cleaned my project and rebuilt, still with no luck, is there something else that i could be missing? does the hibernate configuration gets cached in some file i have to erase or something?

EDIT
For what it may serve, i can connect using SQL developer,the problem is just hibernate still using the old localhost:1521:orcl Connection descriptor.

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

巷子口的你 2024-10-31 02:28:05

验证您在 Eclipse 中更改的 xml 文件是否确实已部署到服务器。我偶尔会遇到问题,Eclipse 不知道它需要为我的 web 应用程序重新部署某些文件。

如果您使用 Tomcat 并使用工作区元数据(默认)进行部署,则可以通过查看以下文件系统来检查实际部署的 WAR 文件:

WORKSPACE/.metadata/.plugins/org.eclipse.wst .server.core/tmp0/wtpwebapps/APPNAME/.../path/to/hibernate.cfg.xml

如果您发现配置文件没有更新,我建议取消部署您的应用程序在Eclipse中,删除上述路径中的整个APPNAME目录,并重新部署clean。

如果这些都不起作用,请在项目范围内搜索“localhost”,看看是否有任何地方可能有任何硬编码的连接字符串。

Verify that the xml file you are changing in Eclipse is actually being deployed to the server. I run into problems every once in awhile where Eclipse doesn't know it needs to redeploy certain files for my webapp.

If you are using Tomcat and deploying using the workspace metadata (the default), you can check what the actual deployed WAR files look like by looking at your filesystem under:

WORKSPACE/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/APPNAME/.../path/to/hibernate.cfg.xml

If you find the config file is NOT being updated, I would recommend undeploying you app in Eclipse, deleting the entire APPNAME directory in the above path, and redeploying clean.

If none of that works, do a project-wide search for "localhost" and see if there could possible be any hardcoded connections strings anywhere.

临风闻羌笛 2024-10-31 02:28:05

此类问题通常是由于存在错误的配置文件造成的。也许您有该文件的两个副本,并且更改了其中一个,但系统正在使用另一个

。通常在构建/编译时,资源会被复制到目标/构建文件夹中。检查源文件夹并构建目标文件夹等。

在文件系统中搜索名称为 hibernate.cfg.xml 或内容为 localhost:1521:orcl 的所有文件。

检查类路径,或尝试先显式放置包含所需配置文件的文件夹在类路径中。

也可能是某些其他配置覆盖您的配置,例如数据源文件管理器或 persistence.xml 文件。如果您也有的话,请检查一下。

您的应用程序运行得如何?通过测试用例、独立控制台应用程序、servlet/j2ee 容器?

This kind of problem is usually due to the wrong configuration file being present. Maybe you have two copies of the file and you changed one but the system is using the other

Typically when building/compiling, resources get copied to a target/build folder. Check source folders and build target folders etc.

Search the file system for all files with the name hibernate.cfg.xml or with the contents localhost:1521:orcl

Check the classpath, or try explicitly putting the folder with the configuration file you want first in the classpath.

It can also be a case of some other configuration overriding your configuration, for instance a datasource filer or a persistence.xml-file. Check those if you have them as well.

How are you running your application? Through a test case, standalone console application, servlet/j2ee container?

煞人兵器 2024-10-31 02:28:05

它无法理解“orcl”SID。 SID 可能存在于您的“localhost”上,但不存在于服务器“10.73.98.230”上。验证您使用的是“10.73.98.230”上可用的正确 SID。

It is unable to understand the "orcl" SID. May be the SID is present on your "localhost" but not on the server "10.73.98.230". verify you are using the correct SID available on "10.73.98.230".

第七度阳光i 2024-10-31 02:28:05

尝试更改配置文件中的这一行。

<property name="hibernate.connection.url">jdbc:oracle:thin:@10.73.98.230:1521:orcl</property>

将//替换为@,

您可以点击包含信息的链接http://www. ryer.co.uk/brian/oracle/ORA12505.htm

希望这会有所帮助

Try changing this line in your config file.

<property name="hibernate.connection.url">jdbc:oracle:thin:@10.73.98.230:1521:orcl</property>

replace // with @

you can follow the link the have infomation http://www.cryer.co.uk/brian/oracle/ORA12505.htm

Hope this will help

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文