-->
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: How to retrive the real object from LinkedObject
PostPosted: Fri Mar 14, 2008 6:08 pm 
Newbie

Joined: Tue Feb 24, 2004 11:35 am
Posts: 9
Location: Sofia, Bulgaria
I have database structure with which is possible to have one object which to point another object. The same idea like the Symbolic Link in Linux/UNIX. This is possible because all complex objects are with global unique identifier and for each identifier I have some additional information part of which is linked object. Everything is working fine except that retrieving the linked object. At the moment I do that manually with the following code:

public void populate(EntityManager em, DataObjectBean dob)
{
List<String> properties = manySidedProperties.get(dob.getClass().getName());
if(properties != null && properties.size() > 0)
{
for(String property : properties)
{
try
{
Class cls = dob.getClass();
String methodName = "get" + property + "Id";
Method method = cls.getMethod(methodName, noParameterTypes);
BigInteger id = (BigInteger)method.invoke(dob, noParameters);
if(id != null)
{
DataObject dataObject = em.find(DataObject.class, id);
if(dataObject == null)
continue;
DataObjectTypeLocal dotLocal = getDataObjectTypeLocal();
DataObjectType dot = dotLocal.getDataObjectType(dataObject.getDataObjectTypeId());
Class valueClass = Class.forName(dot.getDataObjectType());
Object entity = em.find(valueClass, id);
if(entity == null)
continue;

methodName = "set" + property;
method = cls.getMethod(methodName, new Class[] {entity.getClass()});
method.invoke(dob, new Object[] {entity});
}
}
catch(Exception ex)
{
throw new RuntimeException(ex);
}
}
}
}

private static TreeMap<String, List<String>> manySidedProperties;
static
{
manySidedProperties = new TreeMap<String, List<String>>();

properties = Arrays.asList("Recipient", "ShippingAgent");
manySidedProperties.put(Invoice.class.getName(), properties);
}

My question is: Is it possible this to be done automatically with some special select statement or inheritance or something like that?

The working environment is the last version of JPA Hibernate.


Miro.

_________________
Regards,
Miro


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.