Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Bytecode enhancement not working in Hibernate
PostPosted: Wed Sep 13, 2017 4:25 am 
Newbie

Joined: Thu Aug 03, 2017 9:25 am
Posts: 6
Hello,
We move from Kodo to Hibernate and because proxies did not meet the requirements of our business layer (narrowing proxy and casting problems), we decided to use bytecode enhancement in order to avoid lots of changes in our business layer.
However, lazy loading interception does not work for us.
What I did is I put
Code:
@org.hibernate.annotations.Proxy(lazy = false)
annotation on every entity class and
Code:
@org.hibernate.annotations.LazyToOne(org.hibernate.annotations.LazyToOneOption.NO_PROXY)
annotation on every field that that is
Code:
@ManyToOne
or
Code:
@OneToOne
association, so it looks in most cases like:
Code:
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@org.hibernate.annotations.LazyToOne(org.hibernate.annotations.LazyToOneOption.NO_PROXY)

(We had to put that cascade because Kodo used defferred constraints mechanism which is unavailable in Hibernate afaik)
Bytecode Instrumentation task worked and modified compiled classes what can be seen after decompiling.
However if I run a JPQL query like
Code:
select a from Account a where a.name = 'Account_1'
select queries for every @ManyToOne association are issued as well.
Are we missing something important?
We use Hibernate 4.2.18


Top
 Profile  
 
 Post subject: Re: Bytecode enhancement not working
PostPosted: Wed Sep 13, 2017 5:26 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1422
Hibernate 4.2 is too old and many things have changed ever since.

Try with 5.2 or 5.1 and see how it works.

But then, related to this statement:

Quote:
However, lazy loading interception does not work for us.


Maybe you should investigate why the default Proxy mechanism is not working for you. Relying on BE for lazy loading is only needed for lazy @Basic properties or the parent-side @OneToOne.

However, if that's not the case, then you are over-complicated things and gain too little in return.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.