我得到以下错误:
java.lang.NoSuchMethodException: Unknown property 'language' on class 'class java.lang.Class'
使用的休息电话:/Test/rest/Languages/insertobj/Japanese/Swedish%206
我正在使用:org.apache.commons.beanutils.PropertyUtils;
我的 Languages 类中确实有指定的属性“语言”,所以我不确定它为什么会抛出错误。当我这样声明它时它会起作用:
语言 lanobj = new Languages();
//语言类
public class Languages implements java.io.Serializable {
private String language;
private String displayName;
public Languages() {
this.language = null;
this.displayName = null;
}
public Languages(String language, String displayName) {
this.language = language;
this.displayName = displayName;
}
public void setLanguageId(Long languageId) {
this.languageId = languageId;
}
@Column(name = "language", nullable = false, length = 50)
public String getLanguage() {
return this.language;
}
public void setLanguage(String language) {
this.language = language;
}
@Column(name = "displayName", nullable = false, length = 50)
public String getDisplayName() {
return this.displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
}
///资源管理器代码
@Path("{subResources}/insertobj/{language-id}/{displayname-id}")
//@POST
@GET // Using get for the sake of making rest call with browser
@Produces(MediaType.TEXT_HTML)
public String getLanguageById(@PathParam("subResources") String id,
@PathParam("language-id") String language_id,
@PathParam("displayname-id") String displayname_id)
{
try{
Class<?> c = Class.forName("com.test."+id);
PropertyUtils.setProperty(c, "language",language_id);
PropertyUtils.setProperty(c, "displayName",displayname_id);
TransactionManager.createObject(c);
}catch (Exception exc){
exc.printStackTrace();
}
}
//TransactionManager 片段:
public static void createObject(Object entityObject) {
Transaction tx = null;
//SessionFactoryUtil.getInstance().openSession();
Session session = SessionFactoryUtil.openSession();
try {
tx = session.beginTransaction();
session.save(entityObject);
tx.commit();
}
catch (RuntimeException e)
{
if (tx != null && tx.isActive())
{
try
{
// Second try catch as the rollback could fail as well
tx.rollback();
}
catch (HibernateException e1) {
//logger.debug(“Error rolling back transaction”);
}
// throw again the first exception
throw e;
}
}
finally
{
session.close();
}
}