-->
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.  [ 1 post ] 
Author Message
 Post subject: Issues using Criteria and Query
PostPosted: Thu Sep 02, 2010 1:07 pm 
Newbie

Joined: Thu Sep 02, 2010 12:58 pm
Posts: 1
I am new to hibernate and trying to write one small program which just querries oracle db and get the results back. Here is my spring config file entry

<!-- Hibernate SessionFactory -->
<bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="annotatedClasses">
<list>
<value>org.test.beans.User</value>
<value>org.test.beans.Organization</value>
</list>
</property>
</bean>

Here is my User class

@Entity
@Table(name = "USER_DETAIL")
public class User implements Serializable{

private String userID;
private String userName;
private String emailAddress;
private String phoneNumer;

protected Locale locale = Locale.getDefault();

@Id
@Column(name = "USER_ID")
public String getUserID() {
return userID;
}

public void setUserID(String userID) {
this.userID = userID;
}

@Column(name = "USER_NAME", length=80, nullable=true)
public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

@Column(name = "EMAIL")
public String getEmailAddress() {
return emailAddress;
}

public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}

@Column(name = "PHONE_NUMBER")
public String getPhoneNumer() {
return phoneNumer;
}

Here is my class where actually it is querrying db

try {
session = sessionFactory.openSession();
log.fine("UserDAOImpl::getUserInfo::session::"+ session);
//Criteria crit = session.createCriteria(User.class);
//crit.add(eq("userID", userName) );

String hql = "from User where userID = :name";
Query query = session.createQuery(hql);
query.setString("name", userName);
user = (User)query.uniqueResult();

//user = (User)crit.uniqueResult();
log.fine("UserDAOImpl::getUserInfo::user::"+ user);
log.fine("UserDAOImpl::getUserInfo::userName::"+ user.getUserID());
} catch (HibernateException e) {
e.printStackTrace();
} finally {
session.close();
}

I tried using Criteria and Query. but in both the cases I am getting the error

FINE: UserDAOImpl::getUserInfo::session::SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]];ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRemovals=[] collectionUpdates=[]])
org.hibernate.hql.ast.QuerySyntaxException: User is not mapped [ from User where userID = :name]
at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:181)
at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:111)
at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:93)
at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:314)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3355)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3239)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:726)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:577)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:294)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:237)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:98)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1760)



Can you please let me know what I am missing here?

Thanks in advance


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

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.