Does Java – hibernate have to drive database design?

I spent a lot of time reading various articles / tutorials about hibernate yesterday. Although I was shocked by its power, I still had a main focus

It seems that the standard practice is to let hibernate design / generate your database architecture for you, which is a suffocating new concept From the tutorials I've read, you just need to be in your hibernate cfg. Add a new entity to the XML configuration file, annotate any POJO you want with @ entity, and look – hibernate creates a table for you Although it's cool, I want to know some scenes:

>What if you already have a database schema and a schema hibernate wants to generate for you does not match it? What if you have a crazy DBA who refuses to compromise on a predefined (non hibernate) architecture? > What if your reference table contains tens of thousands of records (such as all cities in the world)? Do you have to instantiate and save () thousands of unique POJOs, or is there any way to configure hibernate so that it will respect rather than overwrite the existing data in the table? > What if you want to adjust the performance of the schema / table? This includes indexing, standardizing beyond what hibernate automatically creates? > What if you want to add a constraint or trigger to a table? Indicators?

I think it's basically the following:

It seems that hibernate will create and enforce a specific schema / configuration on your database I wonder how this agenda will conflict with our platform standards, our DBA philosophy, and our ability to adjust / adjust tables with which hibernate interacts

Thank you in advance

Solution

Hibernate provides a default way to map objects to tables - such as several tools / libraries. For simplicity, it prefers convention over configuration

However, if you want to map entities to database tables in different ways, you can explicitly tell hibernate how to map these tables (from simple properties, such as changing table names, to redefining foreign key relationships between related entities and how to maintain these relationships)

If you do this correctly, you don't need to instantiate and save existing data, because it doesn't make sense - the database already contains entity information in exactly the same form as hibernate understands (consider – loading and then saving entities immediately should always be no operation, so you can skip it completely.)

So the short answer to your question is "no" If you don't care about design tables, you can let hibernate adopt reasonable defaults If you really want to design the schema explicitly, you can do this, and then describe the exact schema as hibernate

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>