Hibernate 数据库名称更改给出 MySQLSyntaxErrorException:表不存在
我曾经有一个名为 database
的数据库,并且使用 hibernate 及其模型一切都运行良好。
我删除了
以避免更新或创建,因为它是生产服务器,我们希望手动执行此操作。
我们最近切换到database2,因此我们切换了hibernate 配置文件和所有hibernate XML 模型。
`<class name="com.api.models.database.MmApplications" table="mm_applications" catalog="database2">`
但如果我们迁移数据库、模型和连接,它会继续寻找数据库事件。
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'database.mm_applications' doesn't exist
有人可以帮助我吗?
更新 ----
Hibernate 正在连接到正确的数据库 (database2),但是有一个前缀 database.
使得查询命中 database
而不是 >database2
,当我尝试强制使用default_schema
时,我的查询变成:
`... from database.database2.mm_applications ....`
知道吗?
I used to have a database called database
and everything was working well using hibernate and its models.
I removed <property name="hibernate.hbm2ddl.auto">
to avoid update or create as it's a production server, we want to do it manually.
We recently switched to database2
and so we switched the hibernate configuration file and all the hibernate XML models.
`<class name="com.api.models.database.MmApplications" table="mm_applications" catalog="database2">`
but it keeps looking for database
event if we migrated the database, the models and the connexion.
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'database.mm_applications' doesn't exist
Does someone can help me ?
UPDATE ----
Hibernate is connecting to the right database (database2), but there is a prefix as a prefix database.
making the queries hitting the database
instead of database2
, and when I try to force the default_schema
my queries become :
`... from database.database2.mm_applications ....`
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我的数据库是在 hibernate.connection.url 属性中指定的。你也改变了吗?一个例子是:
jdbc:mysql://localhost/mydatabase
另外,您可能应该将其值设置为
validate,而不是删除
。这样 Hibernate 将确保数据模型与数据库模式匹配。hibernate.hbm2ddl.auto
My database is specified in the
hibernate.connection.url
property. Have you changed that also ? An example would be:jdbc:mysql://localhost/mydatabase
Also, instead of removing
hibernate.hbm2ddl.auto
then perhaps you should set its value tovalidate
. That way hibernate will ensure that the datamodel matches the database schema.我发现了问题,这是使用 hibernate 部署在同一个 tomcat 服务器上的另一个应用程序以及另一个数据库(
database
)与新应用程序发生冲突......仍然有一些奇怪的事情,由连接到任何数据库,hibernate将使用hibernate模型中指定的目录,因此使用catalog.table_name构建请求
希望有一天这可以帮助别人。
I found the problem, It was an other application deployed on the same tomcat server using hibernate as well with another database (
database
) making a conflict with the new application ...There is still something weird, by connecting to any database, hibernate will use the specified catalog in the hibernate models and so constructing the request using the catalog.table_name
Hope this help someone someday.