Hi,
I am trying to use a Trigger to generate the primary key to a simple table in association with Hibernate 3 on Oracle 10g. My code looks like the following:
Code:
Session hibSession = sessionFactory.openSession();
Transaction transac = hibSession.beginTransaction();
// Do it here.
Test testObj = new Test();
testObj.setAvailable(new Long(15));
testObj.setPan(new String("Hello"));
hibSession.save(testObj);
System.out.println("The value of id is:: " + testObj.getId());
transac.commit();
hibSession.disconnect();
hibSession.close();
The relevant part of hbm.xml file looks like the following:
Code:
<id name="id" column="ID" type="java.lang.Long">
<generator class="select">
<param name="key">available</param>
</generator>
</id>
<property
name="available"
type="long"
update="true"
insert="true"
column="AVAILABLE"
/>
The table "deepaktest" has ID and Available fields defined as Number. On running the code, I receive the following error:
Code:
org.hibernate.exception.GenericJDBCException: could not insert: [Test]
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificExceptio
n(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter
.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelp
er.java:43)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntit
yPersister.java:1782)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntit
yPersister.java:2176)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentit
yInsertAction.java:34)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplic
ate(AbstractSaveEventListener.java:252)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(Abstrac
tSaveEventListener.java:169)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId
(AbstractSaveEventListener.java:100)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGene
ratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrR
equestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTran
sient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(
DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpda
te(DefaultSaveOrUpdateEventListener.java:71)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:487)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:482)
at HibernateTest.insertData(HibernateTest.java:38)
at HibernateTest.main(HibernateTest.java:14)
Caused by: java.sql.SQLException: Invalid column type: getLong not implemented f
or class oracle.jdbc.driver.T4CRowidAccessor
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java
:146)
at oracle.jdbc.driver.Accessor.unimpl(Accessor.java:358)
at oracle.jdbc.driver.Accessor.getLong(Accessor.java:496)
at oracle.jdbc.driver.OracleReturnResultSet.getLong(OracleReturnResultSe
t.java:290)
at org.hibernate.id.IdentifierGeneratorFactory.get(IdentifierGeneratorFa
ctory.java:47)
at org.hibernate.id.IdentifierGeneratorFactory.getGeneratedIdentity(Iden
tifierGeneratorFactory.java:35)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntit
yPersister.java:1766)
... 15 more
Any clues as to what am I doing wrong? You may YM me on "dnohwal".
Thanks a lot.
Deepak.