Oracle Sequence creation trouble

Home Forums MyEclipse IDE Spring Development Oracle Sequence creation trouble

This topic contains 4 replies, has 2 voices, and was last updated by Profile photo of Jamie Daniel Jamie Daniel 5 years, 2 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #306797
    Profile photo of Jamie Daniel
    Jamie Daniel
    Member

    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

    @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

    #306807
    Profile photo of davemeurer
    davemeurer
    Member

    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

    #306809
    Profile photo of davemeurer
    davemeurer
    Member

    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

    #306811
    Profile photo of davemeurer
    davemeurer
    Member

    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)

    #306815
    Profile photo of Jamie Daniel
    Jamie Daniel
    Member

    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

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.