Closed GoogleCodeExporter closed 9 years ago
Please can you verify with latest release, 1.4.0 is already out, and I see that
you're using a snapshot ?
Original comment by elaat...@gmail.com
on 3 Jan 2013 at 10:49
Okay, what is the latest release? I found only 1.4.0 and I'm using the latest
snapshot from this site.
https://repository-orika.forge.cloudbees.com/snapshot/ma/glasnost/orika/orika-co
re/1.4.0-SNAPSHOT/
Original comment by m.brezov...@gmail.com
on 3 Jan 2013 at 10:55
1.4.0 is the latest release, and it's available from maven central
Original comment by elaat...@gmail.com
on 3 Jan 2013 at 11:30
But I'm using the release 1.4.0, I tried to use JAR from maven central, but it
still throws the same exception.
Original comment by m.brezov...@gmail.com
on 4 Jan 2013 at 12:14
The problem is that the class you're trying to map is not visible by orika
class loader.
Can you please try to use HibernateUnenhanceStrategy, (example):
MapperFactory factory = new
DefaultMapperFactory.Builder().unenhanceStrategy(new
HibernateUnenhanceStrategy()).build();
BTW If you have a failing test case please attach it to this issue.
Original comment by elaat...@gmail.com
on 4 Jan 2013 at 12:45
I was using HibernateUnenhanceStrategy before thowing this exception. I don't
understand what does invisibility mean, but all classes are public.
Original comment by m.brezov...@gmail.com
on 4 Jan 2013 at 3:43
'visibility' refers to the class-loader hierarchy (it's a bit complicated); in
short, a classloader can't 'see' classes that were loaded by a child
classloader. Tools like CGLib and Javassist typically have to create a separate
child classloader to load the classes they create through enhancement at
runtime.
the class com.example.hibernate.Product$$EnhancerByCGLIB$$b9465553 (in your
stack trace) is a special class created by CGLib at runtime.
What version of Hibernate are you using?
Original comment by matt.deb...@gmail.com
on 9 Jan 2013 at 2:30
Okay, I don't understand background of this problem, but i would like to
resolve it. I use Hibernate version 3.2.5.
Original comment by m.brezov...@gmail.com
on 9 Jan 2013 at 9:54
thanks. it turns out hibernate < 3.3 uses CGLib for proxies and >= 3.3 uses
Javassist, so it may be that our HibernateUnenhanceStrategy is only working
with the Javassist versions. we'll craft an integration tests with 3.2.5 to
verify...
Original comment by matt.deb...@gmail.com
on 10 Jan 2013 at 4:16
I just ran a quick test with what we already have using hibernate 3.2, and
don't get any failures.
Is there anything else about your setup that might help us understand the
problem?
Could you maybe provide an example of the code in your EntityMapper class
and/or the ProductHelper class?
It's hard to do much more unless we can construct an example failing test
case...
Original comment by matt.deb...@gmail.com
on 11 Jan 2013 at 5:53
I remind that this problem occurs after about 10 calling and then it occurs
regularly in every other calling.
I use following configuration:
Apache Tomcat/7.0.23
JVM Version 1.7.0_02-b13
OS Name Windows 7
MySQL connector 5.1.13
METRO 2.0
Spring Framework 3.0.6
Here is ProductHelper - class Product is hibernate class, class ProductDTO is
WS class. It use my own class EntityMapper - see down.
public class ProductHelper {
Session session = null;
EntityMapper<Product,ProductDTO> mapper;
public ProductHelper() {
this.session = HibernateUtil.getSessionFactory().getCurrentSession();
this.mapper = new EntityMapper<Product,ProductDTO>();
}
public List getAll(int idCompany) {
List<ProductDTO> dtoList = null;
try {
org.hibernate.Transaction tx = session.beginTransaction();
Query q = session.createQuery("from Product as product where product.category.user.company ='" + idCompany + "'");
List<Product> productList = (List<Product>) q.list();
dtoList = mapper.map(productList, ProductDTO.class);
} catch (Exception e) {
e.printStackTrace();
}
return dtoList;
}
}
Here is EntityMapper class:
public class EntityMapper<T, S> implements Mapping<T, S> {
// ORIKA
private MapperFactory mapperFactory;
private MapperFacade facade;
public EntityMapper() {
// ORIKA
this.mapperFactory = new DefaultMapperFactory.Builder().build();
DefaultMapperFactory.Builder builder = new DefaultMapperFactory.Builder();
builder.unenhanceStrategy(new HibernateUnenhanceStrategy());
this.mapperFactory = builder.build();
this.facade = mapperFactory.getMapperFacade();
}
@Override
public S map(T srcObject, Class<S> dstType) {
// ORIKA
mapperFactory.registerClassMap(mapperFactory.classMap(srcObject.getClass(), dstType).byDefault().toClassMap());
S dstObject = (S) facade.map(srcObject, dstType);
return dstObject;
}
@Override
public List<S> map(List<T> srcList, Class<S> dstType) {
List<S> dstList = new ArrayList<S>();
for (T t : srcList) {
S dstObject = map(t, dstType);
dstList.add(dstObject);
}
return dstList;
}
}
Original comment by m.brezov...@gmail.com
on 11 Jan 2013 at 10:24
Thanks for the info.
I'd start with a few changes in EntityMapper:
In general, registering a class-map is considered an initialization step,
and only needs to be done once per class (not for every instance)...I have
a guess that registering the classmap every time is probably the issue.
(see comments below).
public class EntityMapper<T, S> implements Mapping<T, S> {
// ORIKA
private MapperFactory mapperFactory;
private MapperFacade facade;
public EntityMapper() {
// ORIKA
// Unneeded statement; gets replaced by the factory built in the
next statements
// this.mapperFactory = new DefaultMapperFactory.Builder()
// .build();
DefaultMapperFactory.Builder builder = new
DefaultMapperFactory.Builder();
builder.unenhanceStrategy(new HibernateUnenhanceStrategy());
this.mapperFactory = builder.build();
this.facade = mapperFactory.getMapperFacade();
}
@Override
public S map(T srcObject, Class<S> dstType) {
// ORIKA
// You don't need this statement; in fact, it may be what's causing
the problem
// In general, registering a classmap each time will be very
in-efficient, and Orika is already
// good enough to register one as needed if you're just using the
defaults
// mapperFactory.registerClassMap(mapperFactory.classMap(srcObject.getClass(),
dstType).byDefault().toClassMap());
S dstObject = (S) facade.map(srcObject, dstType);
return dstObject;
}
@Override
public List<S> map(List<T> srcList, Class<S> dstType) {
List<S> dstList = new ArrayList<S>();
for (T t : srcList) {
S dstObject = map(t, dstType);
dstList.add(dstObject);
}
return dstList;
}
}
Original comment by matt.deb...@gmail.com
on 11 Jan 2013 at 5:44
did you get any chance to try those changes?
Original comment by matt.deb...@gmail.com
on 18 Jan 2013 at 1:50
Hi, I'm sorry for the delay in replying, I would like to thank you for your
suggestions. I've changed my code according to your suggestion. But it still
throws me the same exception.
Original comment by m.brezov...@gmail.com
on 19 Jan 2013 at 12:05
I'm having a bit of trouble reproducing the specific problem -- if you could
provide a test case, that would be very helpful in resolving...
Original comment by matt.deb...@gmail.com
on 21 Jan 2013 at 6:03
Okay, I'll try to prepare simplified test case for you. I'll reply later.
Original comment by m.brezov...@gmail.com
on 21 Jan 2013 at 6:06
Original comment by elaat...@gmail.com
on 8 Mar 2013 at 9:05
Original issue reported on code.google.com by
m.brezov...@gmail.com
on 3 Jan 2013 at 9:49