如何在特定的列序列中使用hibernate生成表? [英] How to generate table using hibernate in a specific column sequence?

查看:197
本文介绍了如何在特定的列序列中使用hibernate生成表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Hibernate 在我的项目中生成Hibernate ORM工具,该工具使用我的POJO类自动生成数据库,但创建的表按排序顺序排列列。如何在我在POJO类中定义属性的顺序中创建表。

I am using Hibernate to generate Hibernate ORM tool in my project which automatically generates database using my POJO class but the created table have columns sequence in sorted order. How can I create a table in the sequence in which I have defined attributes in my POJO class.

例如:如果我已经定义了三个我的POJO类中的属性:

For example: If I have defined three attributes in my POJO class:

String id, name, address;

生成的表将列序列为:地址,id,名称。我希望它具有与我的数据库中的 id,name,address 相同的列序列。我怎样才能做到这一点?

Generated table will have column sequence as: address, id, name. I want it to have same column sequence as: id, name, address in my database. How can I do that?

推荐答案

您的代码永远不应该依赖于数据库中列的顺序。实际上,从技术上讲,当您 SELECT * 时,无法保证按特定顺序返回列。如果您想按特定顺序排列,请在 SQL查询中指定

Your code should never depend on the ordering of columns in the database. In fact, there is technically no guarantee that columns will be returned in a particular order when you SELECT *. If you want the columns in a particular order, specify it in your SQL query.

Hibernate团队表示这是一个已知限制,无法设置订单。但是在生产中使用 Hibernate 时,你不应该依赖 hbm2ddl ,这是非常有限的,例如它可以添加列,但无法将其删除。

Hibernate team says it's a known limitation and it's impossible to set the order. But you shouldn't rely on hbm2ddl when using Hibernate in production, it's pretty limited thing, for instance it can add column, but it can't remove it.

这篇关于如何在特定的列序列中使用hibernate生成表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆