Hi Experts!!
I am using Hibernate3.2 with NetBeans5.5 IDE
all the things work out finely but data is not being inserted my Sybase database table.
Here is my problem in depth ready for your reference:: :-)
1) Table structure (Say table Contact)
columnName type constraints
-----------------------------------------------------------------------
empId int notnull,primary key
firstName nvarchar
lastName nvarchar
email nvarchar
==========================================
2) java file for my table say Contact.java
public class Contact {
int empId;
String firstName;
String lastName;
String email;
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public String getEmail() {
return email;
}
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public void setEmail(String email) {
this.email = email;
}
}
============================================
3) .xml file for the same .... say contact.hbm.xml
<hibernate-mapping>
<class name="roseindia.tutorial.hibernate.Contact" table="Test.mdave.Contact">
<id name="empId" type="int" column="empId" >
<generator class="assigned"/>
</id>
<property name="firstName"/>
<property name="lastName"/>
<property name="email"/>
</class>
</hibernate-mapping>
=========================================
4) My Hibernate configuration file .....
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.sybase.jdbc2.jdbc.SybDriver</property>
<property name="connection.url">jdbc:sybase:Tds:10.100.112.48:5000/Test</property>
<property name="connection.username">mdave</property>
<property name="connection.password">mdave1</property>
<property name="connection.pool_size">10</property>
<property name="dialect">org.hibernate.dialect.SybaseDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<mapping resource="roseindia/tutorial/hibernate/contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>
===============================================
5) This is my mail class file
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class FirstExample {
public static void main(String[] args) {
Session session = null;
try{
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
Contact contact = new Contact();
contact.setEmpId(2);
contact.setFirstName("mike");
contact.setLastName("dave");
contact.setEmail("
[email protected]");
session.save(contact);
System.out.println("Done");
}catch(Exception e){
e.printStackTrace();
System.out.println(e.getMessage());
}finally{
try{
session.flush();
session.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
}
==============================================
6) This is what appear in out put window of NetBeans5.5 IDE
run:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Hibernate: insert into Test.mdave.Contact (firstName, lastName, email, empId) values (?, ?, ?, ?)
BUILD SUCCESSFUL (total time: 16 seconds)
============
Please note that i have used Syabase database and when i run my program it gives me error.....
Thanks U All in Advance !!!!!