Hello All,
I've been trying to get Hibernate to work with Informix on Linux, but have been facing a couple of issues.
Here's the errant piece of code:
Session session = null;
System.out.println("Starting session");
try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
System.out.println("Loading config");
session =sessionFactory.openSession();
System.out.println("Inserting Record");
Contact contact = new Contact();
contact.setId(6);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("
[email protected]");
session.save(contact);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
try {
// Actual contact insertion will happen at this step
session.flush();
session.close();
} catch (Exception e){
e.printStackTrace();
}
}
Pretty standard example, I picked it up from a Hibernate tutorial.
I think I've configured the xmls and classpaths correctly.
Here's the error I received upon running the jar:
Starting session
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment ).
log4j:WARN Please initialize the log4j system properly.
Loading config
Opened session
Inserting Record
Done
org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException (SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.j ava:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelp er.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelp er.java:29)
at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.jav a:384)
at org.hibernate.jdbc.JDBCContext.connect(JDBCContext.java:141)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:88)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.j ava:73)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.j ava:66)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatc her.java:130)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntit yPersister.java:1809)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntit yPersister.java:2171)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.ja va:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutio ns(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlus hEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:94)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa der.java:56)
Caused by: java.sql.SQLException: Transactions not supported
at com.informix.util.IfxErrMsg.getSQLException(IfxErrMsg.java:395)
at com.informix.jdbc.IfxSqliConnect.setAutoCommit(IfxSqliConnect.java:18 41)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnectio n(DriverManagerConnectionProvider.java:112)
at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.jav
... 20 more
Sigh. 20 more to plod through. I'd really appreciate help with the first though.
Help, please! And many thanks!