Hibernate - difference between annotations and commons-annotations? - java

To keep it short and sweet:
There is hibernate-commons-annotations 4.1.0-Final and hibernate-annotations 3.5.6-Final.
I'm a nub, what's the difference between them, and do I need them both?
Trying to "avoid" JPA and by that I mean using the JPA 2.0 standards embedded within Hibernate.
Thanks!

Previously, hibernate-annotations was released and versioned from hibernate core. But from version 3.5 and up it is included with hibernate core. And for some reason it was still released from 3.5.0 to 3.5.6 but you do not need it anymore.
And coming to hibernate-commons-annotations, it is a utility project used by annotations based hibernate sub-projects. It is used by other hibernate projects like hibernate-search and thus is maintained as a separate project and it is a compile time dependency for hibernate-core v3.6.0 and up.
Source 1
Source 2

Hibernate Commons Annotations is "Utility project for annotation handling", as said for example here. It does not contain such API that normal user of Hibernate should use.
Hibernate annotations contained persistence mapping annotations and related code. Nowadays it is merged to Hibernate core.
If you really want to avoid JPA (1/2) that is easily done by not using classes from javax.persistence package or from its subpackages. If you want opposite, use javax.persistence and avoid org.hibernate packages where possible.
Good guide to get started with Hibernate can be found from http://docs.jboss.org/hibernate/orm/4.1/quickstart/en-US/html_single/. It also tells which libraries are needed always and which ones are optional.
Reference documentation contains plenty of advices about using JPA instead of deprecated legacy Hibernate annotations.

Related

Hibernate 4.3.5 - What is the use of the hibernate-entitymanager-4.3.5.Final.jar

In the distribution package of Hibernate version 4.3.5, inside /lib/jpa/ folder we have a hibernate-entitymanager-4.3.5.Final.jar file.
I wanted to know when is this jar used.
Hibernate documentation says that hibernate-entitymanager-4.3.5.Final.jar defines Hibernate support for JPA.
Does it mean that if I want to use Hibernate as JPA provider then I should be using this jar?
Yes, if you plan on using JPA's entity manager and entity manager factory than you should definitely have this jar in your class-path.
You might also include hibernate-jpa-2.0-api or hibernate-jpa-2.1-api to have the JPA reference classes too (interfaces, annotations).
If you use the specific Hibernate API than you only need these modules:
hibernate-core
hibernate-commons-annotations
hibernate-annotations

Query regarding Persistance Framework

I am a bit confused about using the jars to handle database part in Java development:
In my current project, these three jars are being used:
1) ejb3-persistance.jar (#Entiry #Table annotations are taken from this)
2) hibernate3.jar
3) spring-core.jar (JdbcDaoSupport is used from this jar)
Please explain me the details usage of including these jars. (I want to understand the persistance framework in detail).
Please help.
Those annotations are "standard" ejb3 annotations.
Hibernate is the specific ORM being used (it will leverage the "standard" annotations)
Spring is providing the JDBC connection that Hibernate is using.
For more details about what each of these three component frameworks does, I would suggest you visit their respective projects and read their documentation. It's too much for SO.

jboss envers for versioning?

I have entities that required versioning support and from time to time, i will need to retrieve old version of the entity . should i just use
options available
1. http://stackoverflow.com/questions/762405/database-data-versioning
2. jboss envers (can this be used on any web server,tomcat,jetty, appengine) ?
3. any similar library like jboss envers that ease to do versioning?
JBoss Envers can be used always when you're using Hibernate as the persistence provider. It's actually bundled with the new Hibernate 3.5. Envers is a an excellent tool, but I has one drawback - you can version only entities that aggregate versioned entities. This means that if you want to version Entity A and it has fields of types B and C, which are also entities - B and C should be versioned by envers as well - if your entities have a tight coupling(which is bad design, but is fairly possible) you'll have to version the whole project and there is some overhead to that.
We personally opted for a lighter custom versioning solution after we investigated Envers, but if it fits your bill - you should definitely use it. I'm not aware of other tools offering its capabilities.

Is Hibernate deprecated?

This morning I was aboard a S-Bahn (German Subway) and I met a fellow student, who works for IBM. What he is doing there is Java EE optimization. I told him about my little project. And he recommended not to use 'oldschool' Hibernate. That's why my question is:
Is Hibernate deprecated?
(In combination with Java EE/Web Development)
..or did he just prate..
No, Hibernate is not deprecated.
However, there's now JPA (Java Persistence API), which is a standard API for doing the things that Hibernate does.
Note that JPA is just an interface specification. You'll need something that implements JPA, and Hibernate is one of the implementations of JPA. Besides Hibernate, there are a few others such as EclipseLink (the official reference implementation for JPA) and Apache OpenJPA.
Hibernate, apart from being an implementation of JPA, does provide a lot of extra advanced feature that JPA lacks of (extra syntax in query, QBC support etc). Some of them are really useful and hard to find a workaround in JPA world (yet). Without providing such features, it is hard to say JPA can "replace" Hibernate (hence, saying Hibernate being deprecating)
Hibernate is the JPA provider offered by JBoss, which is a Java EE server, so I doubt that Hibernate as an implementation is deprecated.
Perhaps he meant that using Hibernate within a Java EE server , bypassing the container-provider persistence, is deprecated and you should rely on our container for such services.
No, there is no way that Hibernate is deprecated. There is the JPA which is a persistence specification and Hibernate implements it. Also Hibernate has its own advanced features that JPA does not have and that's why Hibernate is the main source of new features that are added to the JPA standard.
One possible reason why he may have suggested you against Hibernate is that for a small project, the overhead of understanding Hibernate can be quite significant.
Hibernate is vast to say the least. Though it can be used in a simple way, but to find that out too, you'll need to comprehend a whole lot more.
but be rest assured that Hibernate is NOT deprecated, or going to be any time in the distant future. it's just that if your ORM needs are modest, you might want to try other solutions like iBATIS
JPA is only one way to do it. There's still Spring and all the other frameworks where Hibernate is well alive.
Based on what you said, it sounds like he may have been referring to Hibernate xml mappings, in contrast to using Hibernate annotations or JPA. XML is most certainly old-school rubbish.

eclipse default jpa implementation library where to download?

In eclipse, the "default implementation library" what jars files do I need to include if I do not want to use server runtime?
I'm refering to this tutorial http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.jpt.doc.user/task_create_new_project.htm
Follow Using TopLink JPA with Dali to get started with the Toplink Essentials (JPA reference implementation). To get the mentioned jars (toplink-essentials.jar and toplink-essentials-agent.jar), download them from there or, if you use Maven, from the Java.Net Maven Repository.
PS: Please note that after 2.0-b36, the toplink-essentials-agent.jar file is no longer needed as the agent facility is now integrated into toplink-essentials.jar. So you can do like below.
$ java -javaagent:toplink-essentials.jar client.Client
Depends on what implementation you want to use. There are currently three most popular implementations: Hibernate, TopLink and EclipseLink.
I know about hibernate that it's README file explains what jars are mandatory for what functions. If you use JPA you must have some sort of EntityManager (hibernate can be used without EntityManager too), so you need all the dependencies of it.
To download hibernate JPA implementation use this link (look for hibernate-entitymanager). You need hibernate core, annotations and entity manager for JPA. If you use all the jars in those three packages you should be ok. But I strongly suggest you to read the README files.

Categories

Resources