-->
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.  [ 4 posts ] 
Author Message
 Post subject: Problem while retreiving values
PostPosted: Wed Nov 25, 2009 1:59 am 
Newbie

Joined: Wed Nov 25, 2009 1:17 am
Posts: 2
Hi,
I'm relatively new to Hibernate. While trying to retrieve values from two tables I'm getting the following error.

Error:
org.hibernate.hql.ast.QuerySyntaxException: Customer is not mapped. [Select C.customerName from Customer C, Account A WHERE A.id.customerId = C.customerId AND A.id.serialId = '2' AND A.id.accountId='102' ]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:157)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:87)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:265)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3049)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2938)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:218)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:158)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:109)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:75)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:54)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:71)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1583)


Main method:
CustomerDAO obj = new CustomerDAO();
Customer customerObj = obj.findByProp(2,102).get(0);
String customerName = customerObj.getCustomerName();
System.out.println("customerName ::" + customerName);

Method in CustomerDAO:
public List<Customer> findByProp(Integer serialId, Integer accountId){
String strHQL = "Select C.customerName from Customer C, Account A WHERE A.id.customerId = C.customerId AND A.id.serialId = '%s' AND A.id.accountId='%s' ";
strHQL = String.format(strHQL, serialId, accountId);
Query queryObject = getSession().createQuery(strHQL);
return queryObject.list();
}

Customer.hbm.xml:

<hibernate-mapping>
<class name="com.pojo.Customer" table="CUSTOMER" schema="SYSTEM">
<id name="customerId" type="java.lang.Integer">
<column name="CUSTOMER_ID" precision="22" scale="0" />
<generator class="assigned" />
</id>
<property name="customerName" type="java.lang.String">
<column name="CUSTOMER_NAME" length="30" />
</property>
<property name="customerNumber" type="java.lang.Integer">
<column name="CUSTOMER_NUMBER" precision="22" scale="0" />
</property>
<set name="accounts" inverse="true">
<key>
<column name="CUSTOMER_ID" precision="22" scale="0" not-null="true" />
</key>
<one-to-many class="com.pojo.Account" />
</set>
</class>
</hibernate-mapping>

Account.hbm.xml:

<hibernate-mapping>
<class name="com.pojo.Account" table="ACCOUNT" schema="SYSTEM">
<composite-id name="id" class="com.pojo.AccountId">
<key-property name="serialId" type="java.lang.Integer">
<column name="SERIAL_ID" precision="22" scale="0" />
</key-property>
<key-property name="accountId" type="java.lang.Integer">
<column name="ACCOUNT_ID" precision="22" scale="0" />
</key-property>
<key-many-to-one name="customer" class="com.pojo.Customer">
<column name="CUSTOMER_ID" precision="22" scale="0" />
</key-many-to-one>
</composite-id>
</class>
</hibernate-mapping>

com.pojo.AccountId:

// Fields

private Integer serialId;
private Integer accountId;
private Customer customer;


// Constructors

/** default constructor */
public AccountId() {
}


/** full constructor */
public AccountId(Integer serialId, Integer accountId, Customer customer) {
this.serialId = serialId;
this.accountId = accountId;
this.customer = customer;
}


Can anyone please help me on this? Is there any problem with my HQL/SQL query ?


Top
 Profile  
 
 Post subject: Re: Problem while retreiving values
PostPosted: Wed Nov 25, 2009 3:15 am 
Newbie

Joined: Wed Nov 25, 2009 1:17 am
Posts: 2
After some research, I was able to get the answer.

Thankyou.


Top
 Profile  
 
 Post subject: Re: Problem while retreiving values
PostPosted: Wed Nov 25, 2009 5:37 am 
Regular
Regular

Joined: Mon Aug 07, 2006 5:07 am
Posts: 56
Was it that your Customer.hbm.xml wasn't included in the SessionFactory / EntityManager in the hibernate configuration?


Top
 Profile  
 
 Post subject: Re: Problem while retreiving values
PostPosted: Thu Dec 24, 2009 10:09 am 
Newbie

Joined: Thu Dec 24, 2009 10:05 am
Posts: 1
Could you write your solution? Maybe other one has same problem, and reading you solution can help a lot.

Thanks


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