March 15, 2010 at 1:56 pm #306797
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.
@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 ?
JamieMarch 16, 2010 at 7:07 am #306807
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
-DaveMarch 16, 2010 at 8:19 am #306809
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…
-DaveMarch 16, 2010 at 8:50 am #306811
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://java.sun.com/developer/technicalArticles/J2EE/jpa/ (search for IdClass)March 16, 2010 at 9:27 am #306815
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….