#what should I take care when writing an ORM

1 messages · Page 1 of 1 (latest)

dusky sundial
#

hey, guys
for interest, I want to write a ORM framework for fun, using the java language,
for now, I have understand the main idea of ORM is translate the java code into SQL,
but I don't know why such popular ORM framework in github has so many code, so I think there must be something I have missing, can you give me suggestion ? 😉

mystic lynxBOT
#

<@&1008423204219531294> please have a look, thanks.

#

Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#
TJ-Bot
Hey, guys for interest, I want to write a ORM framework for fun, using the java language, for now, I have understand the main idea of ORM is translate the java code into SQL, but I don't know why such popular ORM framework in github has so many code, so I

ava objects into database tables and vice versa. When writing an ORM framework, there are a few things you should keep in mind:

  1. Object-Relational Mapping: Make sure to establish a clear mapping between your Java objects and the corresponding database tables. This mapping should be flexible enough to handle different types of relationships and data types.
  2. Performance: ORM frameworks can sometimes introduce overhead due to the translation between objects and tables. Make sure to optimize your framework for performance by minimizing unnecessary queries and data retrieval.
  3. Error Handling: Implement robust error handling mechanisms to handle exceptions that may occur during database operations, such as connection errors or query failures.
  4. Security: Ensure that your ORM framework includes security features to prevent common vulnerabilities such as SQL injection attacks.
  5. Documentation: Provide comprehensive documentation for your ORM framework to help users understand how to use it effectively and troubleshoot any issues that may arise.
    Overall, writing an ORM framework can be a challenging but rewarding experience. By focusing on these key areas, you can create a powerful and efficient tool for interacting with databases in Java.
rain pelican
#

I recommend reading the blog and twitter feed of the JOOQ author, they've shared a lot of their challenges.

#

And yes, you're missing how different some databases behave, connection pooling, etc..

clear ledge
#

the purpose of ORM is not to "just translate java into SQL"

#

or, at least, not limited to it

#

for example, with Hibernate you can directly edit your entities and the changes made will be flushed automatically to the database once the transaction ends

#

this requires much more than simple translation into SQL

#

Hibernate needs to create proxy classes for your entities in order to track where cnahges are made, for example

#

also, there are various levels of caching, if you request the same entity with the same id, Hibernate can skip the trip to database if it is already managed in the current session

#

there is other stuff like validation (checking that your database has all the required tables and columns), entity lifecycle events, custom type converters so that you can map complex types onto fields, support for different database dialects and much more

#

also, can't talk about ORMs without mentioning n+1 problems

dusky sundial
#

I don't know about n + 1, I just want to make it for fun and for study