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