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.  [ 1 post ] 
Author Message
 Post subject: SQL Insert Fails
PostPosted: Wed Sep 28, 2011 4:42 pm 

Joined: Wed Sep 28, 2011 2:39 pm
Posts: 1
I am starting out with this tool and I seem be stuck. I have a simple class that inserts a contact(fname, lname, email)
specs eclipse:indigo, ms sql 2008. When I run the class the following statement is generated (from sql profiler)
declare @p1 int
set @p1=5
exec sp_prepexec @p1 output,N'@P0 nvarchar(4000),@P1 nvarchar(4000),@P2 nvarchar(4000)',
N'insert into Contact (FIRSTNAME, LASTNAME, EMAIL) values (@P0, @P1, @P2)                         
select SCOPE_IDENTITY() AS GENERATED_KEYS',N'Smitha',N'Rao',N'smithaxxx@yahoo.com'
select @p1]

It does not insert and no errors generated when running the class, however when I ran the statement in the the sql editor I get the following error:
Msg 8179, Level 16, State 2, Procedure sp_prepexec, Line 1
Could not find prepared statement with handle 5.

If I comment out the line set@p1=5, then it executes just fine. But this is generated from code. Any help.
This is the xml
<?xml version='1.0'?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping >
   <class name="Contact" table="Contact">
      <id name="id"  column="ID" >
         <generator class="identity" />

      <property name="firstName">
         <column name="FIRSTNAME" sql-type="varchar(50)"  />
      <property name="lastName">
         <column name="LASTNAME" sql-type="varchar(50)"  />
      <property name="email">
         <column name="EMAIL" sql-type="varchar(50)"  />

The main class
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class MyExample {
   public static void main(String[] args) {
      Session session = null;

      try {
         // This step will read hibernate.cfg.xml and prepare hibernate for
         // use
         SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
         session = sessionFactory.openSession();
         // Create new instance of Contact and set values in it by reading
         // them from form object
         System.out.println("Inserting Record");
         Contact contact = new Contact();
      } catch (Exception e) {
      } finally {
         // Actual contact insertion will happen at this step



contact class
public class Contact {
   private String firstName;
   private String lastName;
   private String email;
   private long id;

   public String getEmail() {
      return email;

   public String getFirstName() {
      return firstName;

   public String getLastName() {
      return lastName;

   public void setEmail(String string) {
      email = string;

   public void setFirstName(String string) {
      firstName = string;

   public void setLastName(String string) {
      lastName = string;

   public long getId() {
      return id;

   public void setId(long l) {
      id = l;

Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.