-->
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.  [ 3 posts ] 
Author Message
 Post subject: Cross Session Factory Usage
PostPosted: Wed Feb 22, 2006 1:14 am 
Beginner
Beginner

Joined: Fri May 13, 2005 11:48 am
Posts: 32
I am sure that this just isn't possible but before I give up on it, I thought I would ask here.

I have a class Order mapped in one session factory to a table Order in Database1.

I have another class Category mapped in another session factory to a table Category in Database2.

Order has a property of type Category.

Assuming that these two classes MUST be mapped to different tables in different databases for legacy reasons, how can I get Order to persist to Database1 persisting the Catagory reference to a simple CategoryId column without throwing "An association from the table Order refers to an unmapped class: Category "?


The only answer I can comeup with is:
Just persist the Category Primary Key, then you can just call it out when needed.


Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 9:01 am 
Senior
Senior

Joined: Tue May 10, 2005 9:00 am
Posts: 125
hello

Out of the box, hibernate does not make cross factory management (None that am aware of). However, you could probably play with the event api of Hibernate to do special operation when you object are persisted / loaded.


If you databases are on the same server, with same user / access rights (eg 2 mysql db you have access to, or 2 oracle namespaces), you could try to have only one factory (accessing database1) but with references to tables in the form database2.someTable May be this could do the trick. (This will only work if you can issue a "select * from database2.someTable" while connected to database1).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 22, 2006 10:16 am 
Regular
Regular

Joined: Fri Jun 11, 2004 6:27 am
Posts: 81
Location: Yaroslavl, Russia
You can solve it with custom type:
1. Write a custom type, which will read Category Id from recordset and load necessary Category object from Session 2 (created by Factory 2). For saving it will save the Id of the Category object to the table. Essentially - the same in reverse order.
2. Map your property as a "property" (not "many-to-one", etc.) and specify your custom type.
It shoud be enough.

In general, it's almost your solution "just persist the Category Primary Key", but you will not have to load objects manually.

Please note, that this mapping is not a mapping between entities, so you will have to take care of cascading issues by yourself.

_________________
Best,
Andrew Mayorov // BYTE-force


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.