Announcement Announcement Module
No announcement yet.
roo oracle sequence exception Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • roo oracle sequence exception

    Hi, I tried looking up spring roo forum for similar issue, 89627-ROO-test-doesnot-work-with-Oracle-DB. Ironically I m using roo 1.1.4 which is supposed to have this issue fixed. oracle 11g.

    I added the following annotations to my java class for it to use sequence.
    My sequence is defined in my schema and I m able to execute a select seq.nextval from dual using an external tool.
    But with the app when I try to insert data, I run into sequence not found and it mentions hibernate_seq does not exist. I could not find references of hibernate_seq in all generated files.
    I m not sure of how to make make insert statements use specific sequence than hibernate_seq.

    @RooEntity(identifierField = "pk_id", identifierColumn = "pk_id", table = "TABLE_NAME", schema = "SCHEMA_NAME")
    Any help would be much appreciated.

    thank you,
    Last edited by k_123; Jun 1st, 2011, 03:19 PM.

  • #2
    no replies yet?

    seriously no replies?


    • #3
      Have you tried with another ORM such as EclipseLink?


      • #4
        Hi Alan,
        Thank you for responding. I m not sure why I would be moving away from hibernate. I feel there is an issue with the way code is getting generated or I m not doing it right. Even after adding SequenceGenerator annotation, files generated by roo have no references to that. I found the following link explaining how I can gain control on objects that get generated by roo push-in-refactoring. Unfortunately I m running into a DB maintenance shutdown so I can't verify now, but once it comes up I will verify and let you know
        btw I tried to find a build target where it generates the objects after I edit my .java file, but may be I m not looking at the right place can you help me with that?

        thank you again,
        Last edited by k_123; Jun 1st, 2011, 09:42 PM.


        • #5
          I suggested EclipseLink as this is the reference implementation of the JPA spec and it would be useful to see if the issue still persists. Also, since you have annotated the .java file with @SequenceGenerator, then this is most unlikely a Roo issue, but a Hibernate one. Moreover, Roo does not interpret the @SequenceGenerator annotation anyway. If you want to change the default behavour of how the @Id field is generated, you will need to specify this field in the .java file and change it there


          • #6
            found a solution

            @GeneratedValue(strategy = GenerationType.AUTO,generator="any_name_you_would_like_to_give_to_your_generator")
            After googling, I found a link hibernate sequence generation. They clearly talk about how hibernate sequence generating strategies work. First upon Alan's advice I was convinced that this has something to do with the annotations I was using, so I looked up the web. This link mentions how auto strategy results in hibernate using global hibernate_sequence (which was the error I was getting before). And these annotations should be defined at your key in your java file. I m still using my pull in class, not sure if it is going to work if I create something from scratch, ie., if I change entity java file, is it going to change generated files? I don't know that answer yet.I hope this is going to save someone time!


            • #7

              Finally I got my app working, with oracle sequence defined for every entity. This time without push in refactoring and adding @GeneratedValue and @SequenceGenerator annotations in the format I specified above. There are a few things which you need to be careful while creating an app with oracle. If your keys have a different name other than default "id", you need to define those while generating your entity otherwise, roo will assume that "id" is the default field and try to run an insert using that field resulting in a failure. Here is how you do it:
              field number <name of your PK that uses sequence> --notNull --column <database column name> --type java.lang.Long
              After entity gets generated, you have to add @GeneratedValue and @SequenceGenerator annotations.
              Make sure that version field is defined for all entities as JPA uses it for optimistic locking.

              I m making use of spring mvc as I ran into
              The parameters 'runTarget' for goal org.codehaus.mojo:gwt-maven-plugin run are missing or invalid
              with gwt. I tried to troubleshoot, but had to get one solution tried out so went with mvc. I will try to find a solution for gwt error.
              I have to customize my current app, hope there are some best practices posted some where!


              • #8
                How did you achieve this without the pushin refactoring? The id field is in Foo_Roo_Jpa_Entity aspect file, and we can't add it there since it will be overwritten yes?