-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 54 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject:
PostPosted: Thu Sep 04, 2008 8:58 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 5:24 am
Posts: 40
Location: Luxembourg
landrain wrote:
I haven't tried it, because I don't use annotations, but I think this will work. Add this code on the methods to retrieve the unique identifiers in your classes:[...]


It has been tried (by another member of our dev team) and it works just fine.

I'm looking at a way to declare it globally now, so we don't have to repeat this specific annotation in every class where we want to use it:

Code:
@GenericGenerator(name="triggerAssigned",
  strategy = "jpl.hibernate.util.TriggerAssignedIdentityGenerator"
)


However I have found nothing so far. It seems it's just not possible. That was the same with plain hibernate however: you had to repeat the declaration of your custom id generator for every class. Global declaration of custom id generators would be a nice addition to Hibernate or JPA.


Last edited by landrain on Tue Sep 30, 2008 5:38 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 4:28 am 
Newbie

Joined: Thu Mar 22, 2007 10:39 am
Posts: 14
hi there,

first of all, thanks for your approach on this issue. Seems like a clean way to do this!

Sadly enough, I can't seem to get this to work. My program crashes at the following line:
Code:
insert.executeUpdate();


the stack trace:
Code:
org.springframework.jdbc.UncategorizedSQLException: Hibernate operation: could not insert: [testproject.commontypes.TestObject]; uncategorized SQLException for SQL [insert into TXS031 (INTERFACEID, INTERFACESTATUSCODE, TXS021SEQ, TESTCODE) values (?, ?, ?, ?)]; SQL state [null]; error code [17412]; Bigger type length than Maximum; nested exception is java.sql.SQLException: Bigger type length than Maximum
java.sql.SQLException: Bigger type length than Maximum
   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
   at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
   at oracle.jdbc.driver.T4CMAREngine.buffer2Value(T4CMAREngine.java:2498)
   at oracle.jdbc.driver.T4CMAREngine.unmarshalUB2(T4CMAREngine.java:1182)
   at oracle.jdbc.driver.T4CMAREngine.unmarshalSB2(T4CMAREngine.java:1154)
   at oracle.jdbc.driver.T4CNumberAccessor.processIndicator(T4CNumberAccessor.java:105)
   at oracle.jdbc.driver.T4CNumberAccessor.unmarshalOneRow(T4CNumberAccessor.java:203)
   at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:612)
   at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:219)
   at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:970)
   at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1190)
   at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3370)
   at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3454)
   at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
   at testproject.persistence.TestSequence$Delegate.executeAndExtract(TestSequence.java:144)
   at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
   at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
   at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
   at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)


I'm doubting if it has anything to do with my db-version. I'm using an oracle 8i database (Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production), together with ojdbc 10.2.0.4.0 & Hibernate 3.2.5.ga.

Also, the id in the database is defined as a NUMBER, which I cast to a Long in Java. The query runs perfectly without fetching the sequence.

Maybe someone has a better idea of what's going wrong?

thanks,

Sven


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 4:40 am 
Newbie

Joined: Thu Mar 20, 2008 11:14 am
Posts: 2
Hi Sven,
may be your NUMBER field in the database is bigger than a java.lang.Long.

Regards
Beat


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 5:02 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 5:24 am
Posts: 40
Location: Luxembourg
Sven_Vl wrote:
Sadly enough, I can't seem to get this to work. My program crashes at the following line: [...]
I'm doubting if it has anything to do with my db-version. I'm using an oracle 8i database (Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production), together with ojdbc 10.2.0.4.0 & Hibernate 3.2.5.ga.


Yep. This looks like a db/driver compatibility issue.
The version of your driver is ok for the identity generator to work. However, according to the documentation from Oracle, it can only be used with one of these versions of the database: 11.1.0, 10.2.0, 10.1.0 or 9.2.0.

Oracle doesn't support anymore the versions 8.x.y and 7.x.y of their database, so you'll find other problems by using this driver with this db version. Time for an upgrade of the db ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 5:09 am 
Newbie

Joined: Thu Mar 22, 2007 10:39 am
Posts: 14
landrain wrote:
Sven_Vl wrote:
Sadly enough, I can't seem to get this to work. My program crashes at the following line: [...]
I'm doubting if it has anything to do with my db-version. I'm using an oracle 8i database (Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production), together with ojdbc 10.2.0.4.0 & Hibernate 3.2.5.ga.


Yep. This looks like a db/driver compatibility issue.
The version of your driver is ok for the identity generator to work. However, according to the documentation from Oracle, it can only be used with one of these versions of the database: 11.1.0, 10.2.0, 10.1.0 or 9.2.0.

Oracle doesn't support anymore the versions 8.x.y and 7.x.y of their database, so you'll find other problems by using this driver with this db version. Time for an upgrade of the db ?

too bad that's not my call to make.. However, we are planning to upgrade to 10.x in a couple of months now.

The NUMBER-id shouldn't be a problem, as it is now max 1.000.000.000. I was doubting it would try to return the rowid instead of the key, but debugging showed the right returning parameter (RETURNING TXS031SEQ into ?).


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 5:42 am 
Newbie

Joined: Thu Mar 22, 2007 10:39 am
Posts: 14
*edited* sorry, just made a silly remark :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 5:54 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 5:24 am
Posts: 40
Location: Luxembourg
Sven_Vl wrote:
I was doubting it would try to return the rowid instead of the key, but debugging showed the right returning parameter (RETURNING TXS031SEQ into ?).

Yep. It uses the identity column for the returned value. This is one limitation of this solution, because it doesn't work with composite primary keys. But I have developed it in this way to keep the code simpler: if it were not like this, you would have to declare explicitly the column that has to be returned. Also, composite primary keys is a bad practice that needs to be fixed (by using surrogate keys instead). So, I haven't taken them into account.

You should not doubt about this solution, because it is being used currently in one of the largest projects in production in one of the largest governmental institutions in the world.


Last edited by landrain on Tue Feb 17, 2009 7:49 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 30, 2008 9:56 am 
Newbie

Joined: Thu Mar 22, 2007 10:39 am
Posts: 14
landrain wrote:
You should not doubt about this solution, because it is being used currently in one of the largest projects in production in one of the largest governmental institutions in the world.

I wasn't doubting about the solution itself, I was doubting about the implementation of it in our environment. Still looking for the best work-around for Oracle8i (as I can't touch the db-triggers), I'll be posting if I found something else useful.

thanks for the help!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 24, 2008 9:27 am 
Beginner
Beginner

Joined: Wed May 25, 2005 8:25 am
Posts: 30
Hello all,

I'm trying to use this method to use my oracle trigger for getting my id.

I have a problem for the method :



Code:
protected PreparedStatement prepare(String insertSQL, SessionImplementor session) throws SQLException {
            return session.getBatcher().prepareStatement(insertSQL, keyColumns);
        }


I'm getting this error :

Code:
javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not insert: [com.edhec.usrmgt.model.users.Contact]
   at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:614)
   at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:226)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:197)
   at $Proxy14.persist(Unknown Source)
   at com.edhec.usrmgt.orm.hibernate.mapping.dao.GenericDaoHibernateImpl.create(GenericDaoHibernateImpl.java:51)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy18.create(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
   at com.edhec.usrmgt.dao.impl.FinderIntroductionInterceptor.invoke(FinderIntroductionInterceptor.java:38)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
   at $Proxy19.create(Unknown Source)
   at com.edhec.usrmgt.service.impl.UserManagementServiceImpl.createContact(UserManagementServiceImpl.java:35)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:310)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
   at $Proxy20.createContact(Unknown Source)
   at com.edhec.usrmgt.web.controller.impl.UserManagementControllerImpl.createUser(UserManagementControllerImpl.java:53)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.web.servlet.mvc.multiaction.MultiActionController.invokeNamedMethod(MultiActionController.java:473)
   at org.springframework.web.servlet.mvc.multiaction.MultiActionController.handleRequestInternal(MultiActionController.java:410)
   at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
   at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
   at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
   at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
   at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
   at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
   at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
   at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
   at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
   at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
   at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
   at java.lang.Thread.run(Thread.java:595)
Caused by: org.hibernate.exception.GenericJDBCException: could not insert: [com.edhec.usrmgt.model.users.Contact]
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:64)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2186)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2666)
   at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:71)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:321)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
   at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
   at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:154)
   at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:110)
   at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
   at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:645)
   at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:619)
   at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:623)
   at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:220)
   ... 76 more
Caused by: java.sql.SQLException: Fonction non prise en charge
   at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
   at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
   at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:269)
   at oracle.jdbc.dbaccess.DBError.throwUnsupportedFeatureSqlException(DBError.java:690)
   at oracle.jdbc.driver.OracleConnection.prepareStatement(OracleConnection.java:3548)
   at com.mchange.v2.c3p0.impl.NewProxyConnection.prepareStatement(NewProxyConnection.java:155)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy$LazyConnectionInvocationHandler.invoke(LazyConnectionDataSourceProxy.java:364)
   at $Proxy12.prepareStatement(Unknown Source)
   at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:527)
   at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:131)
   at com.edhec.usrmgt.orm.hibernate.util.TriggerAssignedIdentityGenerator$Delegate.prepare(TriggerAssignedIdentityGenerator.java:44)
   at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:54)
   ... 91 more


Is this a version pb ? ( before changing my jar's got the problem of method not found : org.hibernate.engine.SessionImplementor)

I'm using the latest jars (from the latest entitymanager package)

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2008 11:11 am 
Newbie

Joined: Wed Nov 05, 2008 11:03 am
Posts: 1
Is there a solution from Hibernate v 3

@Id @GeneratedValue(generator="triggerAssigned")
@GenericGenerator(name="triggerAssigned",
strategy = "or.hibernate.id.SelectGenerator"
)
@Column(name="MECA_UID")
public Long getId() { ... }

this is from http://jira.nhibernate.org/browse/NH-1176

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2009 7:44 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 5:24 am
Posts: 40
Location: Luxembourg
mhitrik wrote:
Is there a solution from Hibernate v 3

@Id @GeneratedValue(generator="triggerAssigned")
@GenericGenerator(name="triggerAssigned",
strategy = "or.hibernate.id.SelectGenerator"
)
@Column(name="MECA_UID")
public Long getId() { ... }

this is from http://jira.nhibernate.org/browse/NH-1176

thanks


Some clarification: there is a big difference between the SelectGenerator of Hibernate (used in the config above) and the id generator discussed in this thread.

The SelectGenerator of Hibernate will work by reselecting the newly inserted row, using a defined column of the entity that should be unique but that is not the primary key (a natural key). So, this solution is not very performant and it must be used with caution. But, yes, it's a possible solution with older DB's or if you don't have the possibility to work with the Oracle 10g driver.

The triggerAssignedGenerator discussed in this thread doesn't reselect the value of the newly inserted row. Instead it uses a feature of JDBC3, available in the latest versions of the Oracle driver, to return the value of a column on the insert operation. No additional sql statement is executed and no natural key must be defined in the entity.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2009 7:53 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 5:24 am
Posts: 40
Location: Luxembourg
partyboy wrote:
Hello all,

I'm trying to use this method to use my oracle trigger for getting my id.

I have a problem for the method :

[...]
Caused by: java.sql.SQLException: Fonction non prise en charge
[...]



Sorry for replying so late. "Fonction non prise en charge" means "unsupported operation".
You version of the JDBC driver is too old. Upgrade to a newer one.


Last edited by landrain on Mon Oct 05, 2009 7:18 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Before Insert Trigger and ID generator
PostPosted: Mon Jul 06, 2009 12:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Beat wrote:
The bad thing is that I had to work directly with java.sql and oracle.jdbc.
Maybe someone has a better solution?


Did you try just using the JDBC3 getGeneratedKeys() functionality? That was the whole point of landrain's code as well as the original code he copied from. See his example above, or the original http://fisheye.jboss.org/browse/Hibernate/core/trunk/core/src/main/java/org/hibernate/id/SequenceIdentityGenerator.java?r=16651#l57. Specifically 2 points:
1) Note the version of prepareStatement used.
2) The use of java.sql.Statement#getGeneratedKeys

DISCLAIMER: I have had intermittent success getting Oracle drivers to properly support getGeneratedKeys(). It seemed like it would work in one release, break in the next, and then be back to working in the very next. So ymmv


Top
 Profile  
 
 Post subject: Re: Before Insert Trigger and ID generator
PostPosted: Wed Sep 30, 2009 4:39 am 
Beginner
Beginner

Joined: Thu Dec 23, 2004 5:24 am
Posts: 40
Location: Luxembourg
steve wrote:
DISCLAIMER: I have had intermittent success getting Oracle drivers to properly support getGeneratedKeys(). It seemed like it would work in one release, break in the next, and then be back to working in the very next. So ymmv

No "intermittent success" in my experience. But it's mainly linked to the version of the jdbc drivers, and not the database: I have tested with many different versions of Oracle above the 9.2.0.3, and it always worked when the drivers were at least 10.2.0.1. The problem is that sometimes the developers don't know exactly which version of the driver they're using, for a few reasons:
- they include the jar in their project, but the server has already a driver in its classpath and it uses that one instead.
- Oracle wasn't always very explicit about the version of their driver (no version number, or even wrong version number, in the manifest).
- Some application servers use their own version of the jdbc drivers (Weblogic, to name just one)

This small utility method will tell which driver you're using for a valid connection in parameter and will also tell if your db supports "getGeneratedKeys()":

Code:
import java.sql.*;

public class TestJDBCVersion {
    public static void version(Connection pconnection) {
        try {
            DatabaseMetaData dmd = pconnection.getMetaData();
            System.out.println("DriverVersion: [" + dmd.getDriverVersion() + "]");
            System.out.println("DriverMajorVersion: [" + dmd.getDriverMajorVersion() + "]");
            System.out.println("DriverMinorVersion: [" + dmd.getDriverMinorVersion() + "]");
            System.out.println("DriverName: [" + dmd.getDriverName() + "]");
            System.out.println("URL: [" + dmd.getURL() + "]");
            System.out.println("UserName: [" + dmd.getUserName() + "]");
            System.out.println(dmd.getDatabaseProductName());
            System.out.println(dmd.getDatabaseProductVersion());
            System.out.print("Supports getGeneratedKeys(): ");
            if (dmd.supportsGetGeneratedKeys() )
              System.out.println("true");
            else
              System.out.println("false");

            String ver;
            ver = System.getProperty("java.version");
            System.out.println("The JDK version is " + ver);

        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}


Top
 Profile  
 
 Post subject: Re: Before Insert Trigger and ID generator
PostPosted: Mon Oct 05, 2009 6:22 am 
Newbie

Joined: Mon Oct 05, 2009 6:16 am
Posts: 3
hi
am trying to use the TriggerAssignedIdentityGenerator using anotation and am gettting the error below
plis help


org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.AssertionFailure: null id in com.nx.nxpos.model.AuditTrail entry (don't flush the Session after an exception occurs)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:583)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:224)
at org.mortbay.jetty.servlet.Dispatcher.forward(Dispatcher.java:126)
at com.nx.nxpos.webapp.filter.StaticFilter.doFilterInternal(StaticFilter.java:103)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:118)
at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:52)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:164)
at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:141)
at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:90)
at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:406)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at net.sf.ehcache.constructs.web.filter.GzipFilter.doFilter(GzipFilter.java:75)
at net.sf.ehcache.constructs.web.filter.Filter.doFilter(Filter.java:92)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at com.nx.nxpos.webapp.filter.LocaleFilter.doFilterInternal(LocaleFilter.java:75)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at com.opensymphony.clickstream.ClickstreamFilter.doFilter(ClickstreamFilter.java:42)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:359)
at org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
at org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.ui.rememberme.RememberMeProcessingFilter.doFilterHttp(RememberMeProcessingFilter.java:116)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:172)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:268)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:87)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:61)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
at org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
at org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:371)
at org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:174)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:842)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:648)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)
Caused by: org.hibernate.AssertionFailure: null id in com.nx.nxpos.model.AuditTrail entry (don't flush the Session after an exception occurs)
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:55)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:164)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:120)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:606)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:709)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy47.saveAuditTrail(Unknown Source)
at com.nx.nxpos.webapp.controller.UserFormController.onSubmit(UserFormController.java:121)
at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:267)
at com.nx.nxpos.webapp.controller.BaseFormController.processFormSubmission(BaseFormController.java:148)
at com.nx.nxpos.webapp.controller.UserFormController.processFormSubmission(UserFormController.java:68)
at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:265)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
... 86 more


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 54 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.