Which JPA implementation does Eclipse use? - java

I know the difference between JPA and specific implementation for example Hibernate or EclipseLink, but what I am interested in, when I download for example Eclipse JAVA EE version, and then in my project use javax.persistence package, which implementation does it use? My guess would be EclipseLink or OpenJPA but how do I know?
I am interested in this because I compared performance of Hibernate and javax.persistence package (just few thousand of rows from db) and the performance gap from my point of view was quite big (about a second)

You can choose it in the JPA Facet pane by using the Platform dropdown. See Eclipse documentation.
If you want to use Hibernate, you have to add it manually in the Eclipse Marketplace. See: JPA Creation - Hibernate not showing in platform

Eclipse EE will bundle EclipseLink via the JPA facet you can add to a project, but other than that it doesn't really provide any specific implementation (you can configure it to provide other implementations if you configure with facet with other user libraries). Your implementation is provided either by libraries, or your app server that you are deploying to. For longer term, a more strategic approach would be to explicitly include an implementation either through dependencies (maven) or referring to/using libraries provided by your app server.

Related

Hibernate - difference between annotations and commons-annotations?

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.

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.

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.

Java, Code Generation, and Persistence Frameworks

Are there any Java code generation persistence frameworks?
Something that is "database first" rather than object model first?
I know this is probably heresy in the Java world, I'd just like to know if any frameworks like this exist.
I'm more of a .NET guy these days. So on the .NET-side tools like .NET Tiers or CSLA come to mind.
sure, hibernate and netbeans for example can reverse engineering a database. You may be want to look at:
Hibernate Tools; site in maintenance
netbeans, with recent version of netbeans you can create JPA entities from a JDBC connection
My 2 cents.
The Apache Cayenne ORM framework is able to reverse engineer a database. See here.
I developed jOOQ to exactly suit your needs - so don't worry about the heresy :-)
Check out the examples page or an article on dzone illustrating my motivations of creating such a framework. The main advantages are:
It generates source code
It stays close to SQL by providing a SQL-like DSL in Java
It supports easy access vendor-specific features, such as UDT's, stored procedures
It supports all advanced SQL features, such as UNIONs, nested SELECTs, aliasing, etc
Note that jOOQ is NOT really an OR-mapper. It focuses on the relational datamodel from your RDBMS and doesn't give you the possibility to create your custom object-oriented domain model like Hibernate or JPA do. This is precisely for the reason you mentioned yourself: Something that is "database first" rather than object model first
Checkout EclipseLink project ( plugins for eclipse) , you can generate JPA models from database tables
DB Importer is an Eclipse plug-in that generates JPA classes from a database.
Disclaimer: I am the creator of DB Importer.
Telosys Tools is a free "database first" code generator
See : https://sites.google.com/site/telosystools/
It's an Eclipse plugin, the templates are customizable if necessary
It can generate the persistance layer (JPA) but also the CRUD Screen
( tutorials are here : https://sites.google.com/site/telosystutorial/ )
Many of the Java-based persistence tools include tools to generate code based upon an existing schema. Netbeans will generate JPA (including Session bean facades, if desired). Similarly, JBoss Tools for Eclipse will generate Hibernate JavaBeans for you based upon an existing schema.
I would recommend HiberObjects. It's an Eclipse plugin that can be used to model persistent objects or reverse engineer an existing database. The way it lets you set up unit tests is truly awesome. You can also modify how for instance DAO classes are generated: just modify a Groovy script and all DAO-classes are re-generated. I have encountered a few bugs, but the guy behind it has been very responsive and released fixes in short time. A description and user ratings/comments are found at Eclipse Plugin Central.

Categories

Resources