-->
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 NOT to retrieve an association ?
PostPosted: Thu Oct 08, 2009 5:24 pm 
Newbie

Joined: Fri Jan 05, 2007 1:47 pm
Posts: 7
Hi all,

My question may sound funny, since usually people try to do the opposite, but here's what I have: I have a project that I've recently refactored in several sub-projects, so that it's more modular. Since I've done that, I have problems, maybe because of Hibernate, maybe because of bad design, you will tell me ;-)

I'm using Hibernate annotations 3.3.0.ga .

I have a common project in which I have

Code:
@Entity(name="T_INDICATOR_FROM_FILE")
public class IndicatorFromFile implements Cloneable, Comparable<IndicatorFromFile>,IHasPostActions{
   @ManyToOne
   @JoinColumn(name = "INDICATOR_FROM_FILE_RESOURCE_ID")
   private AbstractLogLinesResource relatedResource;

   @Column(name="INDICATOR_FROM_FILE_DISP_IN_GRAPH")
   private boolean isDisplayableInGraph=false;
...
}

and
Code:
@Entity(name="T_RESOURCE")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class AbstractLogLinesResource implements Cloneable{
      
   @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="RESOURCE_ID")
   private long id;
   
   @ManyToOne
   @JoinColumn(name = "RESOURCE_RELATED_APPLICATION_ID")
   @ForeignKey(name = "FK_RESOURCE_APPLICATION")
   protected Application relatedApplication;
   
   @OneToMany(mappedBy="relatedResource")
   @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
   private Set<IndicatorFromFile> indicatorsToGet=new TreeSet<IndicatorFromFile>();
   
...}


All the implementing classes for AbstractLogLinesResource are in another project, and I would like to keep it that way.

However, for one sub-project, I don't care about the implementation of the AbstractLogLinesResource, I just need to retrieve IndicatorFromFile objects:

Code:
Criteria req = hibernateTemplate.getSessionFactory().getCurrentSession().createCriteria(IndicatorFromFile.class);
      req.createAlias("relatedResource", "resource");
      req.createAlias("resource.relatedApplication","relatedApplication");
      req.add(Restrictions.eq("relatedApplication.code", applicationCode));
      req.add(Restrictions.eq("isDisplayableInGraph", true));
      
      return req.setCacheable(true).list();


When I run this code, I get a "Cannot instantiate abstract class or interface" exception, since the implementing class is unkown in the current project. If I move my implementing classes in the common project, then it works. But with this comes a lot of code that is irrelevant, so I would like to keep them outside, in a specific project.

When I look at the generated SQL, I see that Hibernate tries to retrieve the "relatedResource" association in the "select" clause. I'm not sure this is causing the Exception, but how can I tell Hibernate not to retrieve this association ? Using Projections, I have seen nothing where I could specify whole objects, only properties.

Any idea ?

Thanks in advance

--
Vincent


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.