Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
AW: [eclipselink-users] Multiple generated values in one Entity

Hi, we use triggers on the OracleDB on nearly any Table to insert Creation User/Date and Mutation User/Date.
In the Entity you have to annotate the Fields with @ReturnInsert and/or @ReturnUpdate.
But be aware on @ReturnUpdate with OptimisticLocking.
If you have at least one Field with @ReturnUpdate OptimisticLockingException wouldn't be recognized because you get one Row even the whereclause of the Updatestatement doesn't match one Row. Because of the returnvalues. I solved the Problem by checking the Returned Values in a @PostUpdate - Method. It depends on your Trigger but if the Whereclause of the Updatestatement doesn't match (when optimistic locking occurred) then all the return values are null. So a sample is shown below.

	@PostUpdate
	public void optimisticLockingHook() {
		if(creDate == null && creSign == null && mutDate == null && mutSign == null) {
			throw new OptimisticLockException();
		}
	}

Best Regards
Berner Martin

> -----Ursprüngliche Nachricht-----
> Von: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-
> bounces@xxxxxxxxxxx] Im Auftrag von James Sutherland
> Gesendet: Dienstag, 9. März 2010 16:28
> An: eclipselink-users@xxxxxxxxxxx
> Betreff: Re: [eclipselink-users] Multiple generated values in one
> Entity
> 
> 
> This is not directly supported.  You could use an event, such as
> preInsert to
> assign the generated value using the Session
> getNextSequenceNumberValue()
> API.  This takes the class however, there does not seem to be an API to
> get
> the next sequence number by name (please log a bug for this).
> 
> You may also be able to assign the values on the database, and use
> EclipseLink returning support to return the assigned values.
> 
> Please log an enhancement request for having support for multiple
> generated
> values in a class.
> 
> 
> 
> _es wrote:
> >
> > Hi, Is there any way to define more than one field in one Entity to
> be
> > generated with sequence generator that uses Oracle db sequences? If I
> try
> > to define GeneratedValue + SequenceGenerator annotations for more
> than one
> > field in entity EcliseLink throws an exception that states that it is
> not
> > allowed to have two GeneratedValues in one Entity.
> >
> > Is there any way to go round that or does anyone have any other idea
> how I
> > could use DB sequences to generate values to columns when Entity is
> > inserted?
> >
> 
> 
> -----
> http://wiki.eclipse.org/User:James.sutherland.oracle.com James
> Sutherland
> http://www.eclipse.org/eclipselink/
>  EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
> TopLink
> Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink ,
> http://wiki.oracle.com/page/TopLink TopLink
> Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink
> ,
> http://www.nabble.com/EclipseLink-f26430.html EclipseLink
> Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
> --
> View this message in context: http://old.nabble.com/Multiple-generated-
> values-in-one-Entity-tp27779151p27837260.html
> Sent from the EclipseLink - Users mailing list archive at Nabble.com.
> 
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users



Back to the top