Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate Criteria Query Problem  RSS feed

 
Shifali Rana
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I just want to ask that the following code can add a row in the table. If the logonid doesn't exist in the system then the logonid will give null Or it will create a new row in the table.

Criteria criteria = currentSession.createCriteria(com.test.cs.model.user.User.class);
criteria.add(Restrictions.eq("logonID", logonID));
user = (User)criteria.uniqueResult();

The problem is that initially there is no record in the table for logonid = 1 but on executing the above code it creates an entry in the user table for logonid = 1.

Thanks
 
Christian Dillinger
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that code cannot produce a row in a table. It's a query.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!