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.  [ 2 posts ] 
Author Message
 Post subject: sql like insert syntax in Hql?
PostPosted: Wed Aug 30, 2006 3:34 am 
Newbie

Joined: Mon Aug 21, 2006 4:31 am
Posts: 9
hi

as i have seen insert syntax in HQL is : INSERT INTO ... SELECT
now how can i just insert a new record, from a form, i need not to select it from any other table? like insert into datetable year,month

thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 30, 2006 9:43 am 
Newbie

Joined: Fri Jul 28, 2006 11:22 am
Posts: 4
Hi!
If you want to insert something into a table with hibernate, you need an object for the table.
After creating the object, you can manipulate it.
The changes will be sent to the database by hibernate.

Code:
org.hibernate.Session sess = sessionFactory.openSession();
String statement = "FROM TABLE WHERE ..."
org.hibernate.Query query = sess.createQuery(statement);
YourTableObject entry = null;

// get the specific entry in the database
entry = (YourTableObject) query.uniqueResult();
// set your value(s) via selfmade function(s) in the entry-object
entry.setValue("...");
...

//begin transaction
org.hibernate.Transaction tx = sess.beginTransaction();
//save changes
sess.save(entry);
// commit changes
tx.commit();
//close the session
sess.close();


Hope this will help.


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