-->
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.  [ 3 posts ] 
Author Message
 Post subject: "could not resolve property"
PostPosted: Sun Jun 12, 2011 2:11 pm 
Newbie

Joined: Sun Jun 12, 2011 1:43 pm
Posts: 10
Hello.

Classes and message follows.

Document.java
*************
@Entity
@Table(name="DOCUMENTS")
public class Document {
private String name;
private int[] translateTo;
private int writtenLang;
private Project project;
// private List<Content> content;
private Long id;

public void removeTranslationLang(int lang){

}
public void setDocLang(int lang){

}
public void setId(Long id) {
this.id = id;
}

@Id @GeneratedValue
@Column(name="id")
public Long getId() {
return id;
}
public void setName(String name) {
this.name = name;
}

@Column(name="name")
public String getName() {
return name;
}

public void setProject(Project project) {
this.project = project;
}

@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="project_fk")
public Project getProject() {
return project;
}


}


Project.java
**********
@Entity
@Table(name="PROJECTS")
public class Project extends Organization {

static private final Map<String,Project> allProjects = new HashMap<String,Project>();
private Map<String, Document> documents = new HashMap<String, Document>();
private Long id;

public void setDocuments(Map<String, Document> documents) {
this.documents = documents;
}

@OneToMany(targetEntity=net.translators.logic.documents.Document.class,
cascade=CascadeType.ALL,mappedBy="project")
@MapKey(name="id")
public Map<String, Document> getDocuments() {
if (documents ==null)
documents= new HashMap<String, Document>();
return documents;
}

public void addDocument(Document doc){
documents.put(doc.getId().toString(), doc);
}

public void setId(Long id) {
this.id = id;
}

@Id @GeneratedValue
@Column(name="project_id")
public Long getId() {
return id;
}

public static Map<String,Project> getAllProjects() {
return allProjects;
}

public String toString(){
return "{ID:"+getId()+"}{Name:"+getFirstName()+"}";
}

}


struts.xml <selection>
******************
<!-- Translate Document -->
<action name="translate-document" class="net.translators.actions.TranslateDocumentAction"
method="selectDocument">
<interceptor-ref name="defaultAndloginVerifier" />
<result name="success">/organization/translate-document.jsp</result>
<result name="login" type="redirect">login-user</result>
</action>


<action name="do-translate-document" class="net.translators.actions.TranslateDocumentAction"
method="execute">
<interceptor-ref name="defaultAndloginVerifier" />
<result name="success">/organization/translate-document.jsp</result>
<result name="login" type="redirect">login-user</result>
</action>

<!-- END Translate Document -->


TranslateDocumentAction.java
**************************
public class TranslateDocumentAction extends ActionSupport {

private static final long serialVersionUID = -1752813781713631809L;
private List<Document> documentList;
private List<Content> contentList;
private String project_id; //Project's id
private String document_id;//Document's id

public String execute(){
return SUCCESS;
}

public String selectDocument(){
Session s = HibernateUtil.getSessionFactory().openSession();
if(document_id == null){
documentList= s.createQuery("from Document d where d.project_fk="+project_id).list();
System.out.println(documentList);
}else{
contentList = s.createQuery("from Content c where c.document_fk="+document_id).list();
System.out.println(contentList);
}
s.close();
return SUCCESS;
}

public void validate(){}

public void setProjectList(List<Document> documentList) {
this.documentList = documentList;
}

public List<Document> getProjectList() {
return documentList;
}

public void setId(String id) {
// this.id = id;
}

public String getId() {
// return id;
return null;
}

public void setProject_id(String project_id) {
this.project_id = project_id;
}

public String getProject_id() {
return project_id;
}

public void setDocument_id(String document_id) {
this.document_id = document_id;
}

public String getDocument_id() {
return document_id;
}

public void setContentList(List<Content> contentList) {
this.contentList = contentList;
}

public List<Content> getContentList() {
return contentList;
}
}


Error
******
Code:
Struts has detected an unhandled exception:
Messages:    
could not resolve property: project_fk of: net.translators.logic.documents.Document [from net.translators.logic.documents.Document d where d.project_fk=1]
File:    org/hibernate/persister/entity/AbstractPropertyMapping.java
Line number:    81
Stacktraces
org.hibernate.QueryException: could not resolve property: project_fk of: net.translators.logic.documents.Document [from net.translators.logic.documents.Document d where d.project_fk=1]

    org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:81)
    org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:75)
    org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1465)
    org.hibernate.hql.ast.tree.FromElementType.getPropertyType(FromElementType.java:315)
    org.hibernate.hql.ast.tree.FromElement.getPropertyType(FromElement.java:487)
    org.hibernate.hql.ast.tree.DotNode.getDataType(DotNode.java:611)
    org.hibernate.hql.ast.tree.DotNode.prepareLhs(DotNode.java:263)
    org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:210)
    org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:117)
    org.hibernate.hql.ast.tree.FromReferenceNode.resolve(FromReferenceNode.java:113)
    org.hibernate.hql.ast.HqlSqlWalker.resolve(HqlSqlWalker.java:880)
    org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1330)
    org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4471)
    org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3944)
    org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2047)
    org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:831)
    org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:617)
    org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)
    org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244)
    org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
    org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
    org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
    org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:101)
    org.hibernate.engine.query.HQLQueryPlan.(HQLQueryPlan.java:80)
    org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
    org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
    org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
    org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
    net.translators.actions.TranslateDocumentAction.selectDocument(TranslateDocumentAction.java:29)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
    com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
    net.translators.interceptors.MyValidator.intercept(MyValidator.java:70)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:263)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:133)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:207)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:142)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:166)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:190)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
    org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
    org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:485)
    org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:244)
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383)
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
    java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    java.lang.Thread.run(Thread.java:662)
   



Top
 Profile  
 
 Post subject: Re: "could not resolve property"
PostPosted: Mon Jun 13, 2011 1:54 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
In HQL you should use property names and not column names. The property name is the same as the getter method without the 'get' prefix and the first letter in lower-case. Eg your query should be something like this:

Code:
from Document d where d.project=...


Top
 Profile  
 
 Post subject: Re: "could not resolve property"
PostPosted: Mon Jun 13, 2011 9:53 am 
Newbie

Joined: Sun Jun 12, 2011 1:43 pm
Posts: 10
nordborg wrote:
In HQL you should use property names and not column names. The property name is the same as the getter method without the 'get' prefix and the first letter in lower-case. Eg your query should be something like this:

Code:
from Document d where d.project=...


Oooooh! Thanks a lot!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

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.