-->
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.  [ 5 posts ] 
Author Message
 Post subject: data deleted and no entity found!
PostPosted: Mon Feb 25, 2008 10:27 am 
Newbie

Joined: Mon Feb 25, 2008 6:31 am
Posts: 4
Hi,

I have just started using hibernate and I have a simple application that creates a few tables, (POJO classes mapped) and inserting data in the tables , so far this is successfull. I end the application and start a new test program:
I initialize
(EntityManagerFactory emf = Persistence.createEntityManagerFactory("hibernatetest");
EntityManager = emf.createEntityManager(); )
and next I do a query upon the database I created before and this is the exception thrown:

javax.persistence.NoResultException: No entity found for query
at org.hibernate.ejb.QueryImpl.getSingleResult(QueryImpl.java:84)

That is perfectly understanble, for the data I had previously saved in the database it's cleared off and deleted. Has anyone experienced this before?
Why does the data disappear from the database ? Help Pleaseeee!

Thank you,

Tux


Top
 Profile  
 
 Post subject: Re: data deleted and no entity found!
PostPosted: Mon Feb 25, 2008 11:39 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
I don't think that's your problem. what is the query like and how do you do it?



Farzad-


Top
 Profile  
 
 Post subject: Re: data deleted and no entity found!
PostPosted: Tue Feb 26, 2008 4:54 am 
Newbie

Joined: Mon Feb 25, 2008 6:31 am
Posts: 4
I don't think that's your problem. what is the query like and how do you do it?



Farzad-[/quote]

Hi
Thanks for the prompt reply!

my query looks like this:


public User findUser(String username){


User user = new User();
Query query = em.createNamedQuery("User.byname");
query.setParameter("thename", username);
try {
user = (User)query.getSingleResult();
} catch (NoResultException e) {
e.printStackTrace();
}

return user;
}

I have created a named query that look like this:

(this is the User entity that I am trying to map, insert data and then query)

@Entity
@NamedQuery(name="User.byname",
query="Select r from User r where r.name = :thename")
The Id of the User is the username and that's assigend not auto generated.
Any ideas ?
Thanks a lot!

tux


Top
 Profile  
 
 Post subject: Re: data deleted and no entity found!
PostPosted: Tue Feb 26, 2008 11:34 am 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
I don't see much here except the database you're connected to does not have the user. Are you sure the data exists in the database?



Farzad-


Top
 Profile  
 
 Post subject: found!
PostPosted: Wed Feb 27, 2008 8:26 am 
Newbie

Joined: Mon Feb 25, 2008 6:31 am
Posts: 4
Hi!

Thanks for the replies! Found the error - it was in the persistence.xml where I had set the value to create and drop tables!

Cheers,
Tux


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