MyEclipse: Oracle Sequence creation trouble

jamiedaniel - Mar 15, 2010 - 07:56 PM
Post subject: Oracle Sequence creation trouble
While scaffolding a new project, I do not see an option to create an oralce sequence as part of the entity.

I tried adding it to the following file, but it doesn't seem to like what I am trying to annotate.

in Guideline.java

Code:
@Column(name = "ID", nullable = false)
   @Basic(fetch = FetchType.EAGER)
   @Id
   @XmlElement
   @GeneratedValue(generator = "GuidelineSeq", strategy = GenerationType.SEQUENCE)
   @SequenceGenerator(name = "GuidelineSeq", sequenceName = "seq_guideline_id", allocationSize = 1)
   Integer id;


The sequence doesn't get read or invoked at all by the system.

Any ideas ?

Thanks,
Jamie
davemeurer - Mar 16, 2010 - 01:07 PM
Post subject: RE: Oracle Sequence creation trouble
Hi Jamie,

MyEclipse for Spring does not currently have an editor UI for identity / sequence generators / auto increment capability, but please don't hesitate to vote for this JIRA feature request at https://www.skywayperspectives.org/jira/browse/MOD-1287

Regarding the code, this seems to be a Hibernate JPA Oracle question. I tried on my application locally and couldn't get it to work either, so I'd definitely welcome any Hibernate JPA Oracle Spring experts to the table. One thing to note, is the generated DO has an Identity class, so I'm assuming that has some impact.

I do see a couple alternatives:
1. Create a trigger on NULL entries, explained here http://www.oracle-base.com/articles/misc/AutoNumber.php
2. Create a Named Query or direct query that uses the [SEQ NAME].NEXTVAL

-Dave
davemeurer - Mar 16, 2010 - 02:19 PM
Post subject: RE: Oracle Sequence creation trouble
Well, one assumption was correct...

I was able to get this to work, only if I removed the @IdClass annotation on the Domain Object.

As to what impact the @IdClass has on generators and how to get sequences to work within the IdClass annotation, I'll have to revert to more research. But for now, this should hopefully get you most of the way there...

-Dave
davemeurer - Mar 16, 2010 - 02:50 PM
Post subject: RE: Oracle Sequence creation trouble
Just to close the loop. The research I've recently done seems to suggest that the IdClass is primarily used for Composite primary keys, and the @GeneratedValue doesn't work well with IdClass annotations. We have a JIRA investigating the use of IdClass (https://www.skywayperspectives.org/jira/browse/MOD-2895)

Here are some other good resources on the IdClass:
http://wiki.eclipse.org/Introduction_to_EclipseLink_JPA_(ELUG)#.40IdClass

http://opensource.atlassian.com/projects/hibernate/browse/ANN-257

http://www.java2s.com/Code/Java/JPA/SetIdClassforCompoundKey.htm

http://java.sun.com/developer/technicalArticles/J2EE/jpa/ (search for IdClass)
jamiedaniel - Mar 16, 2010 - 03:27 PM
Post subject: RE: Oracle Sequence creation trouble
Dave,

I found that removing the IdClass causes the sequence to work as desires.

Another thing I have found is that if you place this annotation at the top of the file, then rebuild the artifacts, or clean the project -- your code gets whacked.

If you place it near the variable instead of at the @Entity annotation, the code will be kept during a clean.

Is there a way to request that custom Annotations be spared by the clean etc....

Thanks,
Jamie
All times are GMT - 6 Hours
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits