I have run into a EclipseLink issue with multiple queries running against the DB instead of a single query. I found the below SO threads which provides #BatchFetch annotation solution to help run as one master query
How to do join fetching instead of select fectching with EclipseLink?
How to define the EclipseLink annotation for the following?
But I am using EclipseLink 1.2 and the above annotation's classes are only supported by EclipseLink 2+. Appreciate if you could please help with an alternate solution for 1.2. I tried migrating the entire project to EclipseLink 2 but am running into mapping issues which I have no patience to fix right now.
I am using EclipseLink's JPA
The #BatchFetch annotation just set the mapping to use batch reading. You can do this in EclipseLink 1.2 using a DescriptorCustomizer and using the ForeignReferenceMapping API.
One way is to use a query hint, for example:
query.setHint(QueryHints.BATCH, "c.sourceTable");
In this case the sourceTable relation for all c's will be loaded with a single query, not one per c.
Related
I'm trying to migrate an application from Hibernate 3.4.0.GA to Hibernate 5.1, and after complete the required changes on java code, when I deploy the application I'm watching how Hibernate is trying to create HT_ tables (global temporary), one for each #Inheritance annotated entity.
Searching on Google I've found why the tables are being created.
But in my case we are not allow to change de database to add new tables.
My Inheritance model only has one level of Inheritance and its simple, example
Does anyone knows any alternative representation for a hierarchical table structure that I can use to avoid the HT_ tables creation, or some Hibernate configuration to archive the same purpose?.
I can change the inheritance hierarchy on our entities or the Hibernate configuration. I can also asume an exception on deploy caused by the non creation of the tables if it´s non blocking for the rest of the deploy.
Thank you in advance.
UPDATE 1: New info from Hibernate official forum.
UPDATE 2: The Bug was fixed
UPDATE 3: A blog entry explaining different bulk Strategies related to the issue
As in update one on this link is more info from Hibernate official forum with a possible solution.
UPDATE: Link with the solution
If you use Oracle Database with Spring and not sure where to define property for hibernate can do the following.
Add
spring.jpa.properties.hibernate.hql.bulk_id_strategy: org.hibernate.hql.spi.id.inline.InlineIdsInClauseBulkIdStrategy
In application.yml file from resource folder.
I want to use a many-to-many relation between System & Device. I want the system to know its devices order.
I've seen here that I can do it using #OrderColumn.
How can I do it using hibernate xml configuration instead of annotation?
If you're using Hibernate you could try with
sort="unsorted|natural|comparatorClass"
order-by="column_name asc|desc"
as attributes of your relatonship declaration
#OrderColumn is the JPA annotation introduced in JPA 2.0. This works as an additional feature if we work hibernate through JPA. There is no equivalent replacement in hibernate who work with hibernate directly.
I am using Hibernate in our projects and annotation based configuration for Hibernate Domain Pojo Objects. For Annotations based configuration we have two options
JPA based annotations using javax.persistence.*
Use Hibernate Native Annotations org.hibernate.annotations.*
Currently we use JPA based annotation configuration for our POJO files and Hibernate native API like SessionFactory, Session, etc to open session and perform DB operations.
I have these questions:
Is there any problem mixing both JPA annotations and use Hibernate
native API?
This link explains one such issue
(cascade-jpa-hibernate-annotation-common-mistake)
Please provide your expertise, which type of annotations to use
JPA
Hibernate native
Mix both of them?
Hibernate provides one of the JPA implementations. If you use purely JPA in your code, you are free to change to a different implementation if a requirement arises. For example, EclipseLink/TopLink and OpenJPA are implementations which may be required for a different customer. A comprehensive list of implementations is here.
If you are compelled to use any exotic features provided by hibernate which are not in JPA specification, you should go for hibernate specific APIs in your code base. A related discussion from hibernate forum here.
We mixed some of these annotations since with the version of hibernate we were working those days, some features were not available on the JPA spec at that time. For instance to store a boolean value as a 'Y' or 'N' on th DB you have hibernate types you can use. But no such feature was available with the JPA spec at that time. I do not know about the status now. Also for orphan removal also those days JPA did not have the feature, but now i belive they provide an attribute called orphanRemoval on your cascade options. Also you have certain features such as #BatchSize to increase fetching performance with respect to bags. I am unaware if such features are available on the JPA spec yet.
In my experience, mixing and matching plus points from both would be beneficial given that you have no need of switching from one ORM to another.
I'm currently trying to perform audit logging of changed properties using an Interceptor in Hibernate 2.x.
Problem is, the entity I'm trying to save is a detached object so the previousState array in onFlushDirty method of Interceptor always return null. They say that this can be simply solved by calling merge but that method is not available in Hibernate 2.x. Any tips on how I can workaround the problem?
Also, would you have any ideas on how easy or how hard it is to implement something like merge in an application running Hibernate 2.x?
Thanks!
In Hibernate 2.x, have you tried using saveOrUpdate(Object)? This was the initial workaround provided by Hibernate until they added merge() in Hibernate 3.
Currently I have following scenario with my project :
Implemented Hibernate Configuration files (xml) mapping
Database doesn't have any FK relationship yet
So Now I wanna know that what are the things I need to keep in mind before migrating from hibernate xml configuration to hibernate annotations.
One more thing I wanna specify here is right now with my db i don't have any kind of FK relationship defined....
So obviously I will be applying FK first and then start migrating to annotations...
With this scenario Can anybody have any specific suggestion that I should follow ?
Thanks in advance...
Be very careful. Where I work we do everything with annotations so there shouldn't be any specific limitations as far as I can foretell.
It might be wise to migrate a logic chunk of your code at a time if at all possible. But basically it's just painstakingly running through your code and copying everything from the cofnig xml to your entity classes.