A similar method was used to retrieve data from the database. There are other API's like Hibernate Native API that you can use instead of JPA, but JPA seems to be the standard at this point in time.īefore we jump into Hibernate/JPA I just wanted to show how object relational mapping worked before Hibernate/JPA, first you had to obtain a JDBC connection to the database, then prepare a SQL statement, add data, then execute the statement, this had to be repeated for all object/table mappings, you can see that below code is bulky and messy but it worked. You can see in the below diagram that from the database access layer you use JPA/Hibernate/JDBC to retrieve data from the databse. This is were Hibernate and JPA come in, Hibernate is a Object Relational Mapping framework and JPA is a framework that adds an extra layer of abstraction on top of a JPA provider like Hibernate. Databases use SQL joins, which joins tables together to retrieve data. In Java you use the object graph to walk the associations, for example a Person object may contain references to an Address Object which in turn has references to a PostCode object, in order to get to the PostCode object you have walk both Person and Address objects. In java you use references to associate objects and they can be bi-directional but in databases we use a foreign key which are not directional. Objects have the ability to inherit but database tables do not.ĭatabases use a primary key to identify a row but Java uses both object identity (=) and equality (equals) The object model has various levels of granularity but a database table has only two, tables and columns, for example you could have two classes Person and Address but only one table that contains both this information. There are various types of mismatches between the relational model and the object model: Granularity Object-Relational impedance mismatch is the set of technical difficulties that relate to converting database tables (relational model) into the programming language object structure (object model), basically mapping database tables to objects.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
March 2023
Categories |