I have a CUSTOMER entity which contains a LANGUAGE field. the LANGUAGE is another entity object which comes from another db (sharing geo and language information for different db's). When the CUSTOMER is loaded the LANGUAGE shall be loaded too.
q1: Is it really not possible to configure a db name for an entity? Would seem simple to me. At least in mysql the same connection could be used, even joins are simple.
So I created a LanguageUserType. In the CUSTOMER entity the language persists as a simple string field. And in nullSafeGet() I load the Language entity object using a 2nd SessionFactory with a 2nd xml config file.
q2: Is this the way to go?
q3: If I close the (2nd!) session in nullSafeGet() then I end up with an exception "could not initialize proxy - no Session" for further data loading. Is there anything shared between sessions so that one close() closes all?
If I don't close then all works fine.
Hibernate version: 3
Mapping documents:(annotations)
Code between sessionFactory.openSession() and session.close():
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction transaction = session.beginTransaction();
NamedLanguageEntity ret = (NamedLanguageEntity)session.load(NamedLanguageEntity.class, id);
transaction.commit();
session.close();
Full stack trace of any exception that occurs:
10750 [main] ERROR org.hibernate.LazyInitializationException - could not initialize proxy - no Session
org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:86)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:140)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
at com.optimaize.language.NamedLanguageEntity_$$_javassist_19.clone(NamedLanguageEntity_$$_javassist_19.java)
at com.optimaize.language.LanguageUserType.deepCopy(LanguageUserType.java:28)
at org.hibernate.type.CustomType.deepCopy(CustomType.java:202)
at org.hibernate.type.TypeFactory.deepCopy(TypeFactory.java:397)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:201)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:877)
at org.hibernate.loader.Loader.doQuery(Loader.java:752)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2015)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:59)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:587)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1743)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:366)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:186)
at com.optimaize.util.ArrayUtil.joinCollectionToString(ArrayUtil.java:102)
at com.optimaize.util.ArrayUtil.joinCollectionToString(ArrayUtil.java:96)
at com.optimaize.onomastics.entities.NamedEntity.toString(NamedEntity.java:177)
at java.lang.String.valueOf(Unknown Source)
at java.io.PrintStream.println(Unknown Source)
at com.optimaize.onomastics.entities.Jesus.runTest(Jesus.java:35)
at com.optimaize.onomastics.entities.Jesus.main(Jesus.java:20)
Exception in thread "main" org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:86)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:140)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
at com.optimaize.language.NamedLanguageEntity_$$_javassist_19.clone(NamedLanguageEntity_$$_javassist_19.java)
at com.optimaize.language.LanguageUserType.deepCopy(LanguageUserType.java:28)
at org.hibernate.type.CustomType.deepCopy(CustomType.java:202)
at org.hibernate.type.TypeFactory.deepCopy(TypeFactory.java:397)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:201)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:877)
at org.hibernate.loader.Loader.doQuery(Loader.java:752)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadCollection(Loader.java:2015)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:59)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:587)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:83)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1743)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:366)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:108)
at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:186)
at com.optimaize.util.ArrayUtil.joinCollectionToString(ArrayUtil.java:102)
at com.optimaize.util.ArrayUtil.joinCollectionToString(ArrayUtil.java:96)
at com.optimaize.onomastics.entities.NamedEntity.toString(NamedEntity.java:177)
at java.lang.String.valueOf(Unknown Source)
at java.io.PrintStream.println(Unknown Source)
at com.optimaize.onomastics.entities.Jesus.runTest(Jesus.java:35)
at com.optimaize.onomastics.entities.Jesus.main(Jesus.java:20)
Name and version of the database you are using: mysql 5
|