Not able to persist the object to the database.
We are at a point where we have to decide one way or the other - Pl help as quickly as possible. I am not able to persist this object to the database. Below is the information
Hibernate version:
hibernate2.1.6
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.aol.ic.art.data.vo.RequestVO" table="REQUEST">
<id name="id" column="ID">
<generator class="native"/>
</id>
<property name="requestorDn">
<column name="REQUESTORDN" length="255" not-null="true"/>
</property>
<property name="customerDn">
<column name="CUSTOMERDN" length="255" not-null="true"/>
</property>
<property name="fulfillmentBuildingDn">
<column name="FULFILLMENTBUILDINGDN" length="255" not-null="true"/>
</property>
<property name="fulfillmentRoomNumber">
<column name="FULFILLMENTROOMNUMBER" length="20" not-null="true"/>
</property>
<property name="lastApproverDn">
<column name="LASTAPPROVERDN" length="255" not-null="true"/>
</property>
<property name="nextApproverRoleDn">
<column name="NEXTAPPROVERROLEDN" length="255" not-null="true"/>
</property>
<property name="ticketNumber">
<column name="TICKETNUMBER" length="30" not-null="true"/>
</property>
<property name="state">
<column name="STATUS" length="30" not-null="true"/>
</property>
<property name="requestType">
<column name="TYPE" length="30" not-null="true"/>
</property>
<property name="comments">
<column name="COMMENTS" length="255" not-null="true"/>
</property>
<set name="products" table="REQUEST_PRODUCT_LINK" lazy="true">
<key>
<column name="REQUESTID" not-null="true"/>
</key>
<many-to-many class="com.aol.ic.art.data.vo.ProductVO">
<column name="PRODUCTID" not-null="true"/>
</many-to-many>
</set>
<set name="requestStatuses" inverse="true" lazy="true">
<key column="REQUESTID"/>
<one-to-many class="com.aol.ic.art.data.vo.RequestStatusVO"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
TestHibernateUtils.java
Code:
// 1. Build a Request
RequestVO requestVO = new RequestVO("requestorDn", "customerDn",
"comments", "lastApproverDn", "fulfillmentBuildingDn",
"200200", "nextApproverRoleDn", "ticketNumber", state,
RequestType.SOFTWARE.toString());
logger.info("After creating requestVO");
RequestDAOUtils.create(requestVO);
logger.info("Saving RequestVO");
RequestDAOUtils.java
Code:
public static void makePersistent(RequestVO requestVO)
throws ARTException {
try {
HibernateUtil.beginTransaction();
HibernateUtil.currentSession().saveOrUpdate(requestVO);
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
} catch (HibernateException ex) {
throw new ARTException(ex.getMessage(), ARTError.ARTDB_ERROR);
}
}
HibernateUtil.java
Code:
public class HibernateUtil {
private static final Logger log = Logger.getLogger("com.aol.ic.art");
private static Configuration configuration;
private static SessionFactory sessionFactory;
private static final ThreadLocal threadSession = new ThreadLocal();
private static final ThreadLocal threadTransaction = new ThreadLocal();
private static final ThreadLocal threadInterceptor = new ThreadLocal();
// Create the initial SessionFactory from the default configuration files
static {
try {
configuration = new Configuration();
sessionFactory = configuration.configure().buildSessionFactory();
} catch (Throwable ex) {
log.error("Building SessionFactory failed.", ex);
throw new ExceptionInInitializerError(ex);
}
}
/**
* Returns the SessionFactory used for this static class.
*
* @return SessionFactory
*/
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
/**
* Returns the original Hibernate configuration.
*
* @return Configuration
*/
public static Configuration getConfiguration() {
return configuration;
}
/**
* Rebuild the SessionFactory with the static Configuration.
*
*/
public static void rebuildSessionFactory()
throws ARTException {
synchronized(sessionFactory) {
try {
sessionFactory = getConfiguration().buildSessionFactory();
} catch (Exception ex) {
throw new ARTException(ex.getMessage(), ARTError.ARTDB_ERROR);
}
}
}
/**
* Retrieves the current Session local to the thread.
* <p/>
* If no Session is open, opens a new Session for the running thread.
*
* @return Session
*/
public static Session currentSession()
throws ARTException {
Session s = (Session) threadSession.get();
try {
if (s == null) {
log.debug("Opening new Session for this thread.");
if (getInterceptor() != null) {
log.debug("Using interceptor: " + getInterceptor().getClass());
s = getSessionFactory().openSession(getInterceptor());
} else {
s = getSessionFactory().openSession();
}
threadSession.set(s);
}
} catch (HibernateException ex) {
throw new ARTException(ex.getMessage(), ARTError.ARTDB_ERROR);
}
return s;
}
/**
* Closes the Session local to the thread.
*/
public static void closeSession()
throws ARTException {
try {
Session s = (Session) threadSession.get();
threadSession.set(null);
if (s != null && s.isOpen()) {
log.debug("Closing Session of this thread.");
s.close();
}
} catch (HibernateException ex) {
throw new ARTException(ex.getMessage(), ARTError.ARTDB_ERROR);
}
}
/**
* Start a new database transaction.
*/
public static void beginTransaction()
throws ARTException {
Transaction tx = (Transaction) threadTransaction.get();
try {
if (tx == null) {
log.debug("Starting new database transaction in this thread.");
tx = currentSession().beginTransaction();
threadTransaction.set(tx);
}
} catch (HibernateException ex) {
throw new ARTException(ex.getMessage(), ARTError.ARTDB_ERROR);
}
}
/**
* Commit the database transaction.
*/
public static void commitTransaction()
throws ARTException {
Transaction tx = (Transaction) threadTransaction.get();
try {
if ( tx != null && !tx.wasCommitted()
&& !tx.wasRolledBack() ) {
log.debug("Committing database transaction of this thread.");
tx.commit();
}
threadTransaction.set(null);
} catch (HibernateException ex) {
rollbackTransaction();
throw new ARTException(ex.getMessage(), ARTError.ARTDB_ERROR);
}
}
RequestVO.java
Code:
public RequestVO(String requestorDn, String customerDn, String comments,
String lastApproverDn, String nextApproverRoleDn, String fulfillmentBuildingDn,
String fulfillmentRoomNumber, String ticketNumber,
String state, String requestType) {
this.requestorDn = requestorDn;
this.customerDn = customerDn;
this.comments = comments;
this.lastApproverDn = lastApproverDn;
this.nextApproverRoleDn = nextApproverRoleDn;
this.fulfillmentBuildingDn = fulfillmentBuildingDn;
this.fulfillmentRoomNumber = fulfillmentRoomNumber;
this.ticketNumber = ticketNumber;
this.state = state;
this.requestType = requestType;
}
Full stack trace of any exception that occurs:
Name and version of the database you are using:
Oracle 9.2.0
Debug level Hibernate log excerpt:[/size]
2004-08-11 05:08:21 DEBUG HibernateUtil.beginTransaction(?) - Starting new database transaction in this thread.
2004-08-11 05:08:21 DEBUG HibernateUtil.currentSession(?) - Opening new Session for this thread.
2004-08-11 05:08:21 DEBUG SessionImpl.<init>(555) - opened session
2004-08-11 05:08:21 DEBUG JDBCTransaction.begin(37) - begin
2004-08-11 05:08:21 DEBUG JDBCTransaction.begin(41) - current autocommit status:false
2004-08-11 05:08:21 DEBUG SessionImpl.saveOrUpdate(1386) - saveOrUpdate() unsaved instance
2004-08-11 05:08:21 DEBUG BatcherImpl.logOpenPreparedStatement(196) - about to open: 0 open PreparedStatements, 0 open ResultSets
2004-08-11 05:08:21 DEBUG BatcherImpl.getPreparedStatement(237) - select hibernate_sequence.nextval from dual
Hibernate: select hibernate_sequence.nextval from dual
2004-08-11 05:08:21 DEBUG BatcherImpl.getPreparedStatement(241) - preparing statement
2004-08-11 05:08:21 DEBUG SequenceGenerator.generate(81) - Sequence identifier generated: 63
2004-08-11 05:08:21 DEBUG BatcherImpl.logClosePreparedStatement(203) - done closing: 0 open PreparedStatements, 0 open ResultSets
2004-08-11 05:08:21 DEBUG BatcherImpl.closePreparedStatement(261) - closing statement
2004-08-11 05:08:21 DEBUG SessionImpl.saveWithGeneratedIdentifier(778) - generated identifier: 63
2004-08-11 05:08:21 DEBUG SessionImpl.doSave(825) - saving [com.aol.ic.art.data.vo.RequestVO#63]
2004-08-11 05:08:21 DEBUG HibernateUtil.commitTransaction(?) - Committing database transaction of this thread.
2004-08-11 05:08:21 DEBUG JDBCTransaction.commit(59) - commit
2004-08-11 05:08:21 DEBUG SessionImpl.flushEverything(2242) - flushing session
2004-08-11 05:08:21 DEBUG SessionImpl.flushEntities(2435) - Flushing entities and processing referenced collections
2004-08-11 05:08:21 DEBUG HibernateUtil.rollbackTransaction(?) - Tyring to rollback database transaction of this thread.
2004-08-11 05:08:21 DEBUG JDBCTransaction.rollback(82) - rollback
2004-08-11 05:08:21 DEBUG SessionImpl.afterTransactionCompletion(585) - transaction completion
2004-08-11 05:08:21 DEBUG HibernateUtil.closeSession(?) - Closing Session of this thread.
2004-08-11 05:08:21 DEBUG SessionImpl.close(573) - closing session
2004-08-11 05:08:21 DEBUG SessionImpl.disconnect(3332) - disconnecting session
2004-08-11 05:08:21 DEBUG SessionImpl.afterTransactionCompletion(585) - transaction completion
2004-08-11 05:08:21 FATAL ARTInitServlet.init(?) - Init ART - In catch block identifier of an instance of com.aol.ic.art.data.vo.RequestVO altered from 63 to null