-->
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.  [ 11 posts ] 
Author Message
 Post subject: How to add a criteria from to tables that have been joined w
PostPosted: Thu Dec 14, 2006 6:14 pm 
Regular
Regular

Joined: Fri Nov 03, 2006 4:57 pm
Posts: 60
How to add a criteria from to tables that have been joined with a class with many-to-one relationship:


Error:

java.lang.ClassCastException: com.dao.hibernate.Transactions
org.apache.jsp.pages.ResultPage_jsp._jspService(WSErrorsResultPage_jsp.java:99)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)


Criteria crit = session.createCriteria(Transaction.class);
crit.add(Restrictions.like("department", 10));

in my action I got the error. but when I change it to the below I cant pass the Restriction Parameter:

Criteria crit = session.createCriteria(AssignmentItems.class);
//crit.add(Restrictions.like("department", 10));


it doesnt work since the assignment class does not have a department
column and it is in the transaction class. so how do i provide this
criteria.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 14, 2006 8:49 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
session.createCriteria(AssignmentItems.class)
.createAlias("transactions","transaction")
.add(Expression.gt("transaction", 10)
.list();

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 12:53 pm 
Regular
Regular

Joined: Fri Nov 03, 2006 4:57 pm
Posts: 60
I used what you told me above but I get the following error now...

org.hibernate.QueryException: could not resolve property: transactions of: com.dao.hibernate.transactions
org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1265)
org.hibernate.loader.criteria.CriteriaQueryTranslator.getPathEntityName(CriteriaQueryTranslator.java:190)
org.hibernate.loader.criteria.CriteriaQueryTranslator.createCriteriaEntityNameMap(CriteriaQueryTranslator.java:177)
org.hibernate.loader.criteria.CriteriaQueryTranslator.<init>(CriteriaQueryTranslator.java:83)
org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:58)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1531)
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
com.accuserverx.accucharge.web.SearchWorkListErrorsAction.execute(Unknown Source)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 12:59 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
err i meant

session.createCriteria(AssignmentItems.class)
.createAlias("transactions","transaction")
.add(Expression.gt("transaction.department", 10)
.list();

i suggest reading up the documentation on criteria api

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 3:03 pm 
Regular
Regular

Joined: Fri Nov 03, 2006 4:57 pm
Posts: 60
got the exact same for the above

org.hibernate.QueryException: could not resolve property: transactions of: com.dao.hibernate.transactions
org.hibernate.persister.entity.AbstractPropertyMapping.throwPropertyException(AbstractPropertyMapping.java:43)
org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:37)
org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1265)
org.hibernate.loader.criteria.CriteriaQueryTranslator.getPathEntityName(CriteriaQueryTranslator.java:190)
org.hibernate.loader.criteria.CriteriaQueryTranslator.createCriteriaEntityNameMap(CriteriaQueryTranslator.java:177)
org.hibernate.loader.criteria.CriteriaQueryTranslator.<init>(CriteriaQueryTranslator.java:83)
org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:58)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1531)
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:298)
com.accuserverx.accucharge.web.SearchWorkListErrorsAction.execute(Unknown Source)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 4:12 pm 
Beginner
Beginner

Joined: Thu Oct 12, 2006 6:19 pm
Posts: 34
Location: Guatemala
Hi suzie, you can alternatively to use:

Criteria criteria = session.createCriteria(AssignmentItems.class);
Criteria transactionsCrit = criteria.createCriteria("transaction")
.add(Expression.gt("transaction.department", 10)
.list();

instead to create alias for join table.

I hope this helps

_________________
God is Love


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 5:09 pm 
Regular
Regular

Joined: Fri Nov 03, 2006 4:57 pm
Posts: 60
I tried this and it gives me the same error: My second classes name is Transaction but in all the examples I see them doing transaction with lower case and it says it cant find the property transaction for AssignmentItems.class where as transaction is a separate class.

Criteria criteria = session.createCriteria(AssignmentItems.class);
Criteria transactionsCrit = criteria.createCriteria("transaction")
.add(Expression.gt("transaction.department", 10)
.list();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 5:25 pm 
Beginner
Beginner

Joined: Thu Oct 12, 2006 6:19 pm
Posts: 34
Location: Guatemala
Hi again suzie, I believe you must use:
"Transaction" and "Transaction.department" respectively.

I hope this helps

_________________
God is Love


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 5:44 pm 
Regular
Regular

Joined: Fri Nov 03, 2006 4:57 pm
Posts: 60
Criteria criteria = session.createCriteria(AssignmentItems.class);
Criteria transactionsCrit = criteria.createCriteria("transaction")
.add(Expression.gt("transaction.department", 10)
.list();

in the above statment why cant I use since the above appears as if transaction is a property fo the AssignmentItems class

Criteria transactionsCrit = criteria.createCriteria(Transaction.class)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 15, 2006 7:40 pm 
Regular
Regular

Joined: Fri Nov 03, 2006 4:57 pm
Posts: 60
that worked but now my issues is the I can get the getters and setters for the AssignmentItems class in my jsp but not my transaction class


<%
List result = (List) request.getAttribute("result");
%>
<%
for (Iterator itr=result.iterator(); itr.hasNext(); )
{
com.dao.hibernate.AssignmentItems ai = (com.dao.hibernate.AssignmentItems)itr.next();
com..hibernate.Transactions tr = (com.dao.hibernate.Transactions)itr.next();

%>
<tr><td>

<%=ai.getId()%>
<%=tr.getTransaction()%>
</td></tr>

but that doesnt work why? it says that Transactions is not initialized

this is what I have in my action class:



List ai = session.createCriteria(AssignmentItems.class)
.createCriteria("transaction")
.add(Expression.eq("department", new Integer(10)))
.list();


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 18, 2006 10:36 am 
Beginner
Beginner

Joined: Thu Oct 12, 2006 6:19 pm
Posts: 34
Location: Guatemala
Hi again suzie, are you sure hibernate is using your Transaction class instead transaction attribute in your AssignmentItems class?

_________________
God is Love


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.