Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
[b]1> Message.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="hello.Message" table="Message">
<id name="id" column="ID" >
<generator class="increment"/>
</id>
<property name="text">
<column name="TEXT" />
</property>
</class>
</hibernate-mapping>
2> hibernate.cfg.xml
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="connection.username">scott</property>
<property name="connection.url">jdbc:odbc:test</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="connection.password">tiger</property>
<property name="connection.driver_class">sun.jdbc.odbc.JdbcOdbcDriver</property>
<mapping resource="hello/Message.hbm.xml" />
</session-factory>
</hibernate-configuration>
[/b]
Code between sessionFactory.openSession() and session.close():
Hello Freinds,
I am very new to Hibernate. I am trying to run one Simple aplpication
using it. i am using oracle 9i databse. There are two classes :
1. Message.java (Pesistence with ("Message(id ,text)" table).
-------------------------------------------------------------------------
package hello;
public class Message {
private Long id;
private String text;
// private Message() { }
public Message(){}
public Message(String text) {
this.text = text;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
------------------------------------------------------------------------
2. Main.java
-------------------------------------------------------------------------
package hello;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
Session session = null;
try {
SessionFactory sf = new Configuration().configure().buildSessionFactory();
session = sf.openSession();
Message msg = new Message();
msg.setId(new Long(02));
msg.setText("Pradip");
session.save(msg);
}catch(Exception e) {
System.out.println("Exception : " + e.getMessage());
}finally {
// session.flush();
// session.close();
}
}
}
------------------------------------------------------------------------
Full stack trace of any exception that occurs:
I am getting follwing problem if i make disable session.flush() and close() :
-------------------------------------------------------
Exception : could not insert: [hello.Message]
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
----------------------------------------------------------
Other wise I am getting :
------------------------------------------------------------------
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not insert: [hello.Message]
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1869)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2200)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java: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.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)
at hello.Main.main(Main.java:32)
Caused by: java.sql.SQLException: General error
at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
at sun.jdbc.odbc.JdbcOdbc.SQLBindInParameterBigint(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.setLong(Unknown Source)
at org.hibernate.type.LongType.set(LongType.java:40)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1628)
at org.hibernate.persister.entity.BasicEntityPersister.dehydrate(BasicEntityPersister.java:1594)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1850)
... 9 more
-----------------------------------------------------------------------
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Please let me know ....wht exactly problem with this. I tested the given database config. with JDBC and its working fine...so i think that may be some problem with configuration.
waiting for your reply.......
thanks and regards,
Amit Patel