-->
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: Very simple Table not Mapped Problem
PostPosted: Mon Oct 06, 2008 2:55 am 
Newbie

Joined: Mon Oct 06, 2008 2:50 am
Posts: 3
Using JPA-Hibernate

ORM.XML

<package>com.datesite.user</package>

<entity class="DateUser">
<table name="DATEUSER"/>
<attributes>
<id name="id">
<generated-value strategy="IDENTITY"/>
</id>
<basic name="userName">
<column name="USERNAME"/>
</basic>
<basic name="password">
<column name="PASSWORD"/>
</basic>
<basic name="email">
<column name="EMAIL"/>
</basic>
<basic name="tosVersion">
<column name="TOSVERSION"/>
</basic>
<transient name="all"/>
</attributes>
</entity>

Entity Manager

@Repository
@Transactional
public class EntityManagerDateUser implements DateUserManagerI, Serializable {

private EntityManager em;

public EntityManagerDateUser() {

}

@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
this.em = entityManager;
}

@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
public List getAll() {

return this.em.createQuery("SELECT ID,USERNAME,PASSWORD,EMAIL, TOSVERSION FROM DATEUSER du").getResultList();

}
}

Gives Exception

java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: DATEUSER is not mapped [SELECT ID,USERNAME,PASSWORD,EMAIL, TOSVERSION FROM DATEUSER du]

Scratching my Head why isn't Hibernate finding the Mapping?. Note this is a JPA Mapping.

Any help appreciated.
Thanks
Barry


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2008 8:00 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You should not use table/column names in HQL statments, but class/property names. Eg. try something like this instead:

Code:
SELECT du.id, du.userName, du.password, du.email, du.tosVersion FROM DateUser du


Note that this will return a List with an Object[] in each element. If you want DateUser objects you should simply do:

Code:
FROM DateUser


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 3:00 am 
Newbie

Joined: Mon Oct 06, 2008 2:50 am
Posts: 3
That did the trick. Many thanks!


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.