06-04-2010 06:03 AM
ApplicationContext ac = ApplicationContextHelper.getApplicationContext();
TypeHome th = (TypeHome)ac.getBean("TypeHome");
Type currentType = th.findByQname(typeQName);
protected static ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
public static Type getMyType(String typeQName) {
TypeHome th = (TypeHome)ctx.getBean("TypeHome");
Type currentType = th.findByQname(typeQName);
return currentType;
}
@SuppressWarnings("unchecked")
public Type findByQname(String qname) {
log.debug("finding Type instance by example");
try {
List<Type> results = (List<Type>) getSession().createCriteria(
"com.ptsi.pedroStuff.Type").add(Restrictions.like("name", qname).ignoreCase())
.list();
log.debug("find by example successful, result size: "
+ results.size());
return results.get(0);
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
06-04-2010 07:14 AM
06-04-2010 09:03 AM
06-04-2010 09:31 AM
06-04-2010 09:50 AM
08-30-2011 09:30 AM
Hey, i was trying to update an sql table i made using hibernate, but i cant seem to get the current ApplicationContext.
Im trying to get the ApplicationContext inside the DbNodeServiceImpl class so that everytime a node is created i can update my counter in the table.
I was trying:
ApplicationContext ac = ApplicationContextHelper.getApplicationContext();
TypeHome th = (TypeHome)ac.getBean("TypeHome");
Type currentType = th.findByQname(typeQName);
but this so far only leads to:
"Failed to create content due to error: A valid SecureContext was not provided in the RequestContext"
Can anyone help?
Regards
Edit: In my case this was solved using:protected static ApplicationContext ctx = FacesContextUtils.getWebApplicationContext(FacesContext.getCurrentInstance());
and i used to get a row(that i called Type) from my table(named TypeHome):
public static Type getMyType(String typeQName) {
TypeHome th = (TypeHome)ctx.getBean("TypeHome");
Type currentType = th.findByQname(typeQName);
return currentType;
}
and finally, in my class TypeHome i used this method to get a row or Type that column name that matched the string qname:
@SuppressWarnings("unchecked")
public Type findByQname(String qname) {
log.debug("finding Type instance by example");
try {
List<Type> results = (List<Type>) getSession().createCriteria(
"com.ptsi.pedroStuff.Type").add(Restrictions.like("name", qname).ignoreCase())
.list();
log.debug("find by example successful, result size: "
+ results.size());
return results.get(0);
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
since the name column is unique i only need the first result (hence the results.get(0):smileywink:
hope this helps someone.
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.