|
|
|
|
|
Re: Teneo-hibernate:child object is in an other resource [message #498169 is a reply to message #498116] |
Sun, 15 November 2009 14:19 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Allon,
You have to add the session controller name to the uri otherwise the resources can't find it.
See the usage of the HibernateResource.SESSION_CONTROLLER_PARAM in this description:
http://www.elver.org/hibernate/hibernateresources.html#Shari ng+one+Session+between+Resources%2C+One+transaction+when+sav ing+multiple+resources
gr. Martin
Allon Moritz wrote:
> I think some code will bring some ligth into my problem....
>
> I have a static method creating a session controller:
>
> public static synchronized SessionController getSessionController() {
> if (sessionController == null) {
> try {
> NetworkServerControl server = new NetworkServerControl();
> server.start(null);
> } catch (Exception e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> Properties props = new Properties();
>
> props.setProperty(Environment.DRIVER,"org.apache.derby.jdbc.ClientDriver ");
>
> props.setProperty(Environment.URL,"jdbc:derby://localhost:1527/ShopDB;create=true");
>
>
> props.setProperty(Environment.DIALECT,org.hibernate.dialect. DerbyDialect.class.getName());
>
> props.setProperty(Environment.SHOW_SQL, "true");
> HbDataStore hbds = (HbDataStore) HbHelper.INSTANCE
> .createRegisterDataStore("ShopDB");
> hbds.setProperties(props);
> hbds.setEPackages(new EPackage[] { ShopPackage.eINSTANCE });
> hbds.initialize();
>
> sessionController = new SessionController();
> sessionController.setHbDataStore(hbds);
> SessionController.registerSessionController("ShopDB",
> sessionController);
> }
> return sessionController;
> }
>
>
> the code to create a resource:
>
> private static Resource createResource(String type) {
> getSessionController().getSessionWrapper()
> .beginTransaction();
> String uriStr = "hibernate://?" + HibernateResource.DS_NAME_PARAM
> + "=ShopDB&query1=FROM " + type;
> URI uri = URI.createURI(uriStr);
> final Resource res = new ResourceSetImpl().getResource(uri, true);
> getSessionController().getSessionWrapper()
> .commitTransaction();
> return res;
> }
>
>
> and here is where the problem comes (assumption: there is one product
> with a link to the only pricecategory in the table pricecategory):
>
> PRICE_CATEGORIES_RESOURCE = createResource("PriceCategory");
> PriceCategory cat0 =
> (PriceCategory)PRICE_CATEGORIES_RESOURCE.getContents().get(0 );
> PRODUCTS_RESOURCE = createResource("Product ");
> Product prod = (Product)PRODUCTS_RESOURCE.getContents().get(0);
> PriceCategory cat1 = prod.getPriceCategory();
>
>
> now cat1 and cat0 are not the same object........I understand that they
> are not the same but how can I connect prod with cat0???
>
> really thank you for your patience :d
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
|
Powered by
FUDForum. Page generated in 0.04466 seconds