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)
Code:
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
Code:
<?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" />
</id>
<property name="firstName">
<column name="FIRSTNAME" sql-type="varchar(50)" />
</property>
<property name="lastName">
<column name="LASTNAME" sql-type="varchar(50)" />
</property>
<property name="email">
<column name="EMAIL" sql-type="varchar(50)" />
</property>
</class>
</hibernate-mapping>
The main class
Code:
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();
contact.setFirstName("Smitha");
contact.setLastName("Rao");
contact.setEmail("smithaxxx@yahoo.com");
session.save(contact);
System.out.println("Done");
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
// Actual contact insertion will happen at this step
session.flush();
session.close();
}
}
}
contact class
Code:
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;
}
}