Eclipse generates object classes from a database without pulling associations

I am working on rewriting an application using hibernate with an existing database. This application has all the selected queries, basically this is a reading application.

I am trying to create entity classes from tables using JPA tools in eclipse, since there are no restrictions in the database, the generated model classes have no relationships. The application uses about 100 tables using the application in this database.

I tried to figure out the relationship between tables from existing sql queries, and also use the data in the database. But since there are many tables, this is difficult to do manually.

As the database used by the number of applications, there is no way to force connections in the database

Question:

1. Is there a way to generate objects with relationships if there are no database restrictions?

2. If you need to do it manually, what's the best approach?

+5
source share
3 answers

1. Is there a way to generate entities with if relationships in the database there are no restrictions?

Even if it was possible, it would be very error prone. On which rule can relationships be generated in an idiomatic and reliable way?

2. If you need to do it manually, what's the best approach?

If I were in your place, I would have done everything safely.
Manually adding all the relationships between objects after generating entities can be error prone and cumbersome.

Suppose you make mistakes during the entity generation phase (and you can see the number of tables), and you want to generate them again while you have already added a dozen and a dozen relationships to your entities.
By starting the generation again, you will lose all these manually added relationships in the entity.
You must start from scratch.

I think you should do the opposite.

You can, for example, create a copy of the database (I mean the copy, because I believe that if you do not have restrictions on the tables, it is intentional) and adds restrictions on the tables of the database copy.
Then, from these tables with the specified restrictions, you can create objects with all the necessary relationships.

This method provides two advantages :

  • The ability to provide quick feedback on whether the PK / FK restrictions you want to add are compatible with your existing data.

  • the ability to act in stages and be able to take some steps back if necessary.
    For example, if you made mistakes during the entity creation phase (and you could make them see the number of tables), you can repeat the generation phase without losing the automatically generated relationship that arises from the PK / FK restrictions that you added to the tables.

+5
source

There is no direct way to create all entity classes with the required relationships.

But if you want to add relationships to the generated objects, the easiest way, which, I believe, provides a link to Table Combination .

You can follow the link for more information.

http://help.eclipse.org/luna/index.jsp?topic=%2Forg.eclipse.jpt.doc.user%2Ftasks024.htm

+3
source

Unfortunately, OP ( Chris ) was not observed after almost 4 months, so there may be some time (if ever) before we can get more detailed information from Chris, for example, which Sybase software is used (ASE, SQLAnywhere , IQ, Advantage)?

From the point of view of Sybase ASE, there are several areas that I would like to explore:

  • run sp_helpkey to see if any primary / foreign / public keys are described; the disadvantage of this is that these types of keys are for documentation purposes only (i.e. they provide nothing) and often time is not updated over time (i.e. even if some exist, they may be outdated)

  • run sp_helpconstraint (without arguments) to find out if there are any reference restrictions defined in the database; any restrictions may be better than none

  • If this is a production database, find out if the dev / test / pre-prod database versions have any RI restrictions; (for example, performance) to maintain / verify RI restrictions, so it was not found that RI restrictions exist in databases other than prod (to ensure that the new RI code matches), while RI restrictions are dropped in the prod database (assuming that all code promoted to production is “guaranteed” must comply with the requirements of RI)

  • check for triggers (sysobjects.type = 'TR'; sysobjects.type = 'U' and deltrig / instrig / updtrig! = 0); some databases, especially databases that have been since before the dinosaurs, implement RI through triggers; so it may be possible to get some RI restrictions by looking at the startup code

  • last but not least, is there anyone in the company that answers or will know where to look for a (corporate) data model and / or entity diagram for this system; maybe just maybe this database wasn’t developed “on the fly” or “next to someone” (and maybe Santa really exists, huh?)

-2
source

Source: https://habr.com/ru/post/1265035/


All Articles