• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Few questions on Hibernate

 
raja singh kumar
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) I am unable to get the difference between relational database and a non-relational database. Is it not true when we have a database or table it is always relational? Can we have unrelated data in tables?

2)Hibernate is known to handle data types on its own. But I see that in the <Class>.hbm.xml we are mentioning the data type. So where exactly is the automatic data type handling in hibernate?

 
Tim Holloway
Saloon Keeper
Posts: 18359
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll try not to get too inaccurate on this.

A typical real-world database often consists of a dozen or more tables. Some of those tables are likely to be self-contained (independent) relating to no other table. A good example might be one that records log messages.

What distinguishes a relational-DBMS such as Oracle from a non-relational database such as MongoDB is that the DBMS itself supports internal connections between tables (relations). Maintaining and chasing these relationships, supporting join queries and so forth is an expensive thing to do, which is why for high-performance systems non-relational DBMS's have become popular. Both have their places.

You're dealing with some old stuff if you're seeing hbm.xml files. Hibernate now supports the Java Persistence Architecture (JPA), which is part of the JEE standard, I believe. And JPA supports annotations in the class file source. XML is still available, but it's now rarely used - mostly when it's necessary to override the class definition but you don't want to alter the source code for that class.

Regardless, I think the data type that you're seeing in the hbm.xml files is the DBMS native data type and not the Java Persistence Entity Model data type. There is not a precise mapping between Java data types and DBMS data types. In fact, even different DBMS's have different sets of data types. Some of the most popular ones don't even have a BOOLEAN data type, for example.
 
raja singh kumar
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q) The whole purpose of using dependency injection is to keep the individual classes as independent as possible. By using annotation inside the entity class instead of an external XML based approach, aren't we defeating the whole purpose of using dependency injection which is to keep classes as independent as possible?

Q)Definition of mappedBy
"mappedBy refers to the property name of the association on the owner side."

Is the above just a line about mappedBy or is it the definition of mappedBy? What exactly is meant by owner side? Who decides which is the owner side?
 
Tim Holloway
Saloon Keeper
Posts: 18359
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A) The JPA annotations export attribute about the Entity. You would be correct about the IoC issue if the annotations imported external information.

IoC works with a wiring framework, be it JSF, JPA, CDI, or whatever. These frameworks work via wiring configuration files (such as JSF's faces-config.xml), IoC class introspection and/or annotation scanning. So the IoC classes don't reference each other directly, but they do provide information that the wiring framework can use to assemble them together.

A) The "owning" class for JPA entities is the one that actually has a database foreign key in it. In the case of 2-way key references, it would be the "parent" class.

Yes, that's the definition of mappedBy, but it's also its signature characteristic. A much better explanation can my found in my venerable Apress book "Pro JPA 2", and I'm sure in many other sources.
 
Anton Golovin
Ranch Hand
Posts: 527
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
raja singh kumar wrote:1) I am unable to get the difference between relational database and a non-relational database. Is it not true when we have a database or table it is always relational? Can we have unrelated data in tables?

2)Hibernate is known to handle data types on its own. But I see that in the <Class>.hbm.xml we are mentioning the data type. So where exactly is the automatic data type handling in hibernate?



Hi, Raja,

For NoSQL, there is no requirement to have data in different tables be "related" via a foreign key. Hence, it is not relational. NoSQL is good when you have massive amounts of data that cannot scale with the relational approach; then, you use parallel computing to bring down execution times to manageable limits.

Hibernate and other ORMs shine in converting between relational and object-based paradigms so you don't have to.

With best regards,

Anton.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic