-->
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.  [ 5 posts ] 
Author Message
 Post subject: Native Oracle functions for @Id
PostPosted: Wed Mar 04, 2009 10:54 am 
Beginner
Beginner

Joined: Wed Jun 07, 2006 12:28 pm
Posts: 22
Hibernate version:3.2.4.sp1
Persistence Provider: Oracle 10g

We're use the native Oracle function sys_guid() to generate surrogate keys. We're struggling to automate this using Hibernate JPA.

The default value for those fields is a call to sys_guid(), so we decided to try @GeneratedValue(AUTO), assuming Oracle would figure out that it's not actually a sequence, but a function.

Alas, Oracle's "introspection" is not that far along. Clearly Oracle thinks it's of type sequence. Anyone had success calling a native function for @Ids?

Code:
09:39:18,687 FATAL [application] javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not get next sequence value
javax.faces.el.EvaluationException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not get next sequence value
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:91)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:91)
at javax.faces.component.UICommand.broadcast(UICommand.java:383)
at org.ajax4jsf.component.AjaxViewRoot.processEvents(AjaxViewRoot.java:321)
at org.ajax4jsf.component.AjaxViewRoot.broadcastEvents(AjaxViewRoot.java:296)
at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:253)
at org.ajax4jsf.component.AjaxViewRoot.pro
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 04, 2009 11:10 am 
Newbie

Joined: Thu May 22, 2008 9:48 am
Posts: 13
Could you show your setup for the Id (xml or annotations)?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 04, 2009 11:41 am 
Beginner
Beginner

Joined: Wed Jun 07, 2006 12:28 pm
Posts: 22
Code:
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "ADDRESSES_ID", unique = true, nullable = false, length = 32)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 04, 2009 12:40 pm 
Newbie

Joined: Thu May 22, 2008 9:48 am
Posts: 13
I'm not seeing anything for sys_guid() though there is something very similar called org.hibernate.id.GUIDGenerator that says it's for SQL Server but it uses a call (unless this is really old)
Code:
...from GUIDGenerator...
final String sql = session.getFactory().getDialect().getSelectGUIDString();
...from Oracle9iDialect...
public String getSelectGUIDString() {
   "select rawtohex(sys_guid()) from dual";
}

which is available from Oracle9iDialect and hence Oracle10gDialect. I'd think the xml of using this would be:
Code:
<id name="id" type="long" column="ADDRESS_ID">
<generator class="org.hibernate.id.GUIDGenerator"/>
</id>


Code:
@Id
@GeneratedValue(generator="name-of-genericgen")
@GenericGenerator(name="name-of-genericgen", strategy = "guid")
...or maybe...
@GenericGenerator(name="name-of-genericgen", strategy = "org.hibernate.id.GUIDGenerator")
@Column(name = "ADDRESSES_ID", unique = true, nullable = false, length = 32)
Another alternative would be org.hibernate.id.UUIDHexGenerator...I'm really not sure why GUIDGenerator doesn't explicitly support Oracle though. Try it out...I'm not positive about this.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 10, 2009 1:54 am 
Beginner
Beginner

Joined: Wed Jun 07, 2006 12:28 pm
Posts: 22
The former approach worked. Here is the final snip:

Code:
@Id
@GenericGenerator(name = "generator", strategy = "guid", parameters = {})
@GeneratedValue(generator = "generator")
@Column(name = "ADDRESSES_ID", unique = true, nullable = false, length = 32)


Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

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.