-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: mapping across databases
PostPosted: Sat Jan 31, 2009 7:25 am 
Newbie

Joined: Sat Jan 31, 2009 6:57 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.