<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[JavaRanch: Latest posts for the topic "How to Insert values through HQL Insert :-("]]></title>
		<link>http://www.coderanch.com/forums/t/78/Object-Relational-Mapping/Insert-values-through-HQL-Insert</link>
		<description><![CDATA[Latest messages posted in the topic "How to Insert values through HQL Insert :-("]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>How to Insert values through HQL Insert :-(</title>
				<description><![CDATA[HI Everybody,<br />              Can any one of you help me,How to insert values in HQL Insert<br />              Here i am providing sample code...and i am hard coding the values and insert the values in the table.Can anyone please change my code <br /> so tht i can insert the values through HQL Insert(Provide the HQL in my code)<br />  <br />  <br /> <pre> 
//package com.tnzi;
//
//public class main {
//
//}
package com.tnzi;
 
import org.hibernate.Session;
 
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
 
import util.HibernateUtil;
 
public class Main {
 
public static void main(String[] args) {
try{
Set addSet = null;
//Employee_Business_Group employee_Business_Group = null;
Employee employee = null;
//Main mn = new Main();

employee = new Employee();
employee.setLogin_Id(&quot;2223&quot;);
employee.setEmployee_First_Name(&quot;aaaa&quot;);
employee.setEmployee_Last_Name(&quot;q&quot;);
employee.setEmployee_Status_Cd(&quot;A&quot;);
employee.setUpdate_User(&quot;Bhaskar&quot;);
employee.setGlobal_Site_Name(&quot;yahoo&quot;);
employee.setUpdate_Date(new Date());

employee = new Employee();
employee.setLogin_Id(&quot;7777&quot;);
employee.setEmployee_First_Name(&quot;tntntn&quot;);
employee.setEmployee_Last_Name(&quot;xq&quot;);
employee.setEmployee_Status_Cd(&quot;A&quot;);
employee.setUpdate_User(&quot;Bhaar&quot;);
employee.setGlobal_Site_Name(&quot;rediff&quot;);
employee.setUpdate_Date(new Date());

// for first person
addSet = new HashSet();
Employee_Business_Group employee_Business_Group = new Employee_Business_Group();
employee_Business_Group.setBusiness_Group_Id(1);
employee_Business_Group.setPrimary_Business_Group(&quot;F&quot;);
employee_Business_Group.setUpdate_User(&quot;T44444&quot;);
employee_Business_Group.setUpdate_Date(new Date());

addSet.add(employee_Business_Group);

employee_Business_Group = new Employee_Business_Group();
employee_Business_Group.setBusiness_Group_Id(2);
employee_Business_Group.setPrimary_Business_Group(&quot;B&quot;);
employee_Business_Group.setUpdate_User(&quot;T44444&quot;);
employee_Business_Group.setUpdate_Date(new Date());

addSet.add(employee_Business_Group);

employee.setEmployee_Business_Group(addSet);
System.out.println(employee);
createAndStoreEmployee(employee);

HibernateUtil.getSessionFactory().close();
}catch(Exception e){
e.printStackTrace();
}

}
 
private static void createAndStoreEmployee(Employee employee) throws Exception{

Session session = HibernateUtil.getSessionFactory().getCurrentSession();
 
session.beginTransaction();
System.out.println(employee);
session.save(employee);
 
session.getTransaction().commit();
}

}
</pre> <br />  <br /> Thanks & Regards,<br /> Bhaskar<br />  <br /> [Edited to use code tags - Paul Sturrock ]<br /> [ June 19, 2007: Message edited by: Paul Sturrock ]<br /> ]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/217380/1032036</guid>
				<link>http://www.coderanch.com/forums/posts/preList/217380/1032036</link>
				<pubDate><![CDATA[Tue, Jun 19 2007 00:14:00 MDT]]></pubDate>
				<author><![CDATA[Vijay Bhaskar]]></author>
			</item>
			<item>
				<title>How to Insert values through HQL Insert :-(</title>
				<description><![CDATA[Why do you want to do this using HQL? What happens when you run the code you posted above?]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/217380/1032037</guid>
				<link>http://www.coderanch.com/forums/posts/preList/217380/1032037</link>
				<pubDate><![CDATA[Tue, Jun 19 2007 02:15:00 MDT]]></pubDate>
				<author><![CDATA[Paul Sturrock]]></author>
			</item>
			<item>
				<title>How to Insert values through HQL Insert :-(</title>
				<description><![CDATA[My task is to insert the data through HibernateQueryLanguage thats why i requested for you people to help me.Can you please do that for me]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/217380/1032038</guid>
				<link>http://www.coderanch.com/forums/posts/preList/217380/1032038</link>
				<pubDate><![CDATA[Wed, Jun 20 2007 00:03:00 MDT]]></pubDate>
				<author><![CDATA[Vijay Bhaskar]]></author>
			</item>
			<item>
				<title>How to Insert values through HQL Insert :-(</title>
				<description><![CDATA[OK. Well the reason I ask why you want to do it in HQL, is because HQL only supports insert from another table, so:<br /> <pre>
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
String insertStatement = &quot;insert into Object (id, name) select oo.id, oo.name from OtherObject oo&quot;;
s.createQuery( insertStatement ).executeUpdate();
tx.commit();
session.close(); 
</pre><br /> would be how you do it. <br />  <br /> Looking at your code above however there is no other table to select from.]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/217380/1032039</guid>
				<link>http://www.coderanch.com/forums/posts/preList/217380/1032039</link>
				<pubDate><![CDATA[Wed, Jun 20 2007 02:21:00 MDT]]></pubDate>
				<author><![CDATA[Paul Sturrock]]></author>
			</item>
			<item>
				<title>How to Insert values through HQL Insert :-(</title>
				<description><![CDATA[<blockquote class="uncited">
			<div>Originally posted by Vijay Bhaskar:<br /> My task is to insert the data through HibernateQueryLanguage thats why i requested for you people to help me.Can you please do that for me</div>
		</blockquote><br />  <br /> Please keep it nice. If read in the tone I think it is read it is being a bit bossy and not nice.<br />  <br /> It also sounds to me if you have a task like this then it isn't a job related task, because the original code would be the way to do it, using the save() or persist() method. It sounds like a classroom or job interview task, which we don't give answers away for those.<br />  <br /> Mark]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/217380/1032040</guid>
				<link>http://www.coderanch.com/forums/posts/preList/217380/1032040</link>
				<pubDate><![CDATA[Wed, Jun 20 2007 12:32:00 MDT]]></pubDate>
				<author><![CDATA[Mark Spritzler]]></author>
			</item>
	</channel>
</rss>
