- This topic has 4 replies, 2 voices, and was last updated 14 years, 8 months ago by Jamie Daniel.
-
AuthorPosts
-
Jamie DanielMemberWhile 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
@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
davemeurerMemberHi 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
davemeurerMemberWell, 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
davemeurerMemberJust 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)#.40IdClasshttp://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)
Jamie DanielMemberDave,
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 -
AuthorPosts