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: Unable to insert a new row in the table from Java program
PostPosted: Wed Mar 23, 2011 12:52 pm 
Newbie

Joined: Wed Mar 23, 2011 12:34 pm
Posts: 1
Hi,

I executed the below Java code.
HibernateFactory.buildSessionFactory();
SessionFactory sessionFactory= HibernateFactory.getSessionFactory();
HibernateTemplate template= new HibernateTemplate(sessionFactory);
Event event = new Event();
event.setName("Spring");
template.saveOrUpdate(event);


And the Event class has the setName() method
/**
* @hibernate.property column="name"
* @return
*/
public String getName() { return name; }
public void setName(String name) { this.name = name; }



And the hibernate.cfg.xml file has the below mapping for name

<class name="Event" table="events">
<id name="id" column="uid" type="long">
<generator class="increment"/>
</id>
<property name="name" type="string"/>
<property name="startDate" column="start_date" type="date"/>
<property name="duration" type="integer"/>
</class>


The program runs without and error or exception and the following sql query is being printed in the console
Hibernate: insert into events (name, start_date, duration, uid) values (?, ?, ?, ?)

But the record is not getting inserted into table.

Let me know if I am missing something. Thanks in advance.

Regards,
Ganesh


Top
 Profile  
 
 Post subject: Re: Unable to insert a new row in the table from Java program
PostPosted: Wed Mar 23, 2011 4:24 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Seems like you are missing code for transaction management. See http://docs.jboss.org/hibernate/core/3. ... nonmanaged for some generic examples. Don't know how HibernateTemplate comes into play here though. I guess it is from Spring so you might need to check Spring documentation as well for more information.


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.