Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
I've read every topic, studied every reference...i don't seem to be doing anything wrong, the example i've gone for is so simple!!! but it's still not working!!! i need this to work so that i can make something a bit more complicated to work also:
Hibernate version:3.0
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.cme.chatter.bean.Person" table="person">
<id column="id" name="id" type="java.lang.Long">
<generator class="native"/>
</id>
<property column="name" length="45" name="name" not-null="true" type="java.lang.String"/>
<set name="emails" inverse="true">
<key column="person_id"/>
<one-to-many class="com.cme.chatter.bean.PersonEmails"/>
</set>
</class>
<class name="com.cme.chatter.bean.PersonEmails" table="person_emails">
<id column="id" name="id" type="java.lang.Long">
<generator class="native"/>
</id>
<property column="email" length="45" name="email" not-null="true" type="java.lang.String"/>
<many-to-one column="person_id" name="personId" class="com.cme.chatter.bean.Person" not-null="true" />
</class>
</hibernate-mapping>
Java Objects:
public class Person implements Serializable {
/** identifier field */
private Long id;
/** persistent field */
private String name;
private Set emails = new HashSet();
/** full constructor */
public Person(String value) {
this.name = value;
}
/** default constructor */
public Person() {
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String value) {
this.name = value;
}
public String toString() {
return new ToStringBuilder(this)
.append("id", getId())
.toString();
}
public Set getEmails() {
return emails;
}
public void setEmails(Set emails) {
this.emails = emails;
}
}
*********************************
public class PersonEmails implements Serializable {
/** identifier field */
private Long id;
/** persistent field */
private Integer personId;
/** persistent field */
private String email;
/**
*default constructor
*/
public PersonEmails() {
}
/**
* @return Returns the email.
*/
public String getEmail() {
return email;
}
/**
* @param email The email to set.
*/
public void setEmail(String email) {
this.email = email;
}
/**
* @return Returns the id.
*/
public Long getId() {
return id;
}
/**
* @param id The id to set.
*/
public void setId(Long id) {
this.id = id;
}
/**
* @return Returns the personId.
*/
public Integer getPersonId() {
return personId;
}
/**
* @param personId The personId to set.
*/
public void setPersonId(Integer personId) {
this.personId = personId;
}
}
Code between sessionFactory.openSession() and session.close():
Query q = hibSession.createQuery("FROM Person as person LEFT OUTER JOIN Person.emails as emails");
List list = q.list();
for (int i=0; i<list.size(); i++) {
Object[] item = (Object[])list.get(i);
Person p = (Person)item[0];
Set s = new HashSet();
s = p.getEmails();
String[] emails = (String[]) s.toArray();
ChatLog.debug("name: " + p.getName(), PhoneCallsAction.class);
ChatLog.debug("emails: ", PhoneCallsAction.class);
for (int j=0; j<emails.length; j++) {
ChatLog.debug(emails[j], PhoneCallsAction.class);
}
}
Full stack trace of any exception that occurs:
2005-11-17 17:23:21,205 [http-8080-Processor4] DEBUG - find: FROM Person as person LEFT OUTER JOIN Person.emails as emails
2005-11-17 17:23:21,205 [http-8080-Processor4] DEBUG - named parameters: {}
2005-11-17 17:23:21,205 [http-8080-Processor4] DEBUG - parse() - HQL: FROM com.cme.chatter.bean.Person as person LEFT OUTER JOIN Person.emails as emails
2005-11-17 17:23:21,205 [http-8080-Processor4] DEBUG - --- HQL AST ---
\-[QUERY] 'query'
\-[SELECT_FROM] 'SELECT_FROM'
\-[FROM] 'FROM'
+-[RANGE] 'RANGE'
| +-[DOT] '.'
| | +-[DOT] '.'
| | | +-[DOT] '.'
| | | | +-[DOT] '.'
| | | | | +-[IDENT] 'com'
| | | | | \-[IDENT] 'cme'
| | | | \-[IDENT] 'chatter'
| | | \-[IDENT] 'bean'
| | \-[IDENT] 'Person'
| \-[ALIAS] 'person'
\-[JOIN] 'JOIN'
+-[LEFT] 'LEFT'
+-[OUTER] 'OUTER'
+-[DOT] '.'
| +-[IDENT] 'Person'
| \-[IDENT] 'emails'
\-[ALIAS] 'emails'
2005-11-17 17:23:21,205 [http-8080-Processor4] DEBUG - throwQueryException() : no errors
2005-11-17 17:23:21,205 [http-8080-Processor4] DEBUG - query() << begin, level = 1
2005-11-17 17:23:21,205 [http-8080-Processor4] DEBUG - FromClause{level=1} : com.cme.chatter.bean.Person (person) -> person0_
2005-11-17 17:23:21,236 [http-8080-Processor4] ERROR - *** ERROR: Invalid path: 'Person.emails'
2005-11-17 17:23:21,246 [http-8080-Processor4] DEBUG - Invalid path: 'Person.emails'
Invalid path: 'Person.emails'
at org.hibernate.hql.ast.LiteralProcessor.lookupConstant(LiteralProcessor.java:85)
at org.hibernate.hql.ast.DotNode.resolve(DotNode.java:172)
at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:87)
at org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:262)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3022)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2841)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2719)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:513)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:371)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.cme.chatter.action.TestAction.execute(TestAction.java:52)
at com.cme.commons.action.HibernateAction.execute(HibernateAction.java:41)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Unknown Source)
2005-11-17 17:23:21,246 [http-8080-Processor4] DEBUG - query() : finishing up , level = 1
2005-11-17 17:23:21,246 [http-8080-Processor4] DEBUG - processQuery() : ( SELECT ( FromClause{level=1} person person0_ ) )
2005-11-17 17:23:21,246 [http-8080-Processor4] DEBUG - Derived SELECT clause created.
2005-11-17 17:23:21,246 [http-8080-Processor4] DEBUG - Using FROM fragment [person person0_]
2005-11-17 17:23:21,246 [http-8080-Processor4] DEBUG - query() >> end, level = 1
2005-11-17 17:23:21,246 [http-8080-Processor4] DEBUG - --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT' querySpaces (person)
+-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
| +-[SELECT_EXPR] SelectExpressionImpl: 'person0_.id as id' {FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=person,role=null,tableName=person,tableAlias=person0_,colums={,className=com.cme.chatter.bean.Person}}}
| \-[SQL_TOKEN] SqlFragment: 'person0_.name as name28_'
\-[FROM] FromClause: 'FROM' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[person], fromElementByTableAlias=[person0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
\-[FROM_FRAGMENT] FromElement: 'person person0_' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=person,role=null,tableName=person,tableAlias=person0_,colums={,className=com.cme.chatter.bean.Person}}
2005-11-17 17:23:21,246 [http-8080-Processor4] ERROR - com.cme.chatter.action.TestAction - EXIT FAIL execute() org.hibernate.hql.ast.QuerySyntaxError: Invalid path: 'Person.emails' [FROM com.cme.chatter.bean.Person as person LEFT OUTER JOIN Person.emails as emails]
2005-11-17 17:23:21,256 [http-8080-Processor4] DEBUG - closing session
Name and version of the database you are using: MySQL 4.1