Announcement Announcement Module
Collapse
No announcement yet.
Spring Roo and Hibernate @SQLDelete Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Roo and Hibernate @SQLDelete

    Hello all,

    Has anyone had any success with using the Hibernate specific annotation of @SQLDelete in a Roo entity?

    I want to implement soft delete but have not had much success. Ideally, I'd like to be able to do this from a mapped superclass. But I need to get this working first.

    I'm using:
    • STS 2.8
    • Roo 1.2M1
    • JPA with Hibernate as my provider
    • MariaDB


    Found this information HERE though it is a bit dated.


    Code:
    ...
    @SQLDelete(sql="UPDATE client SET active = (0) WHERE id = ?")
    public class Client extends Person { 
    ...
    Upon attempting to delete from my app, I'm getting the following error in the STS console.

    Code:
     ERROR org.hibernate.util.JDBCExceptionReporter - Parameter index out of range (2 > number of parameters, which is 1).
    A point in the right direction would be most appreciated.

    Thanks!

  • #2
    Why the brackets?

    Just wondering - why are there brackets round the zero?

    I would have thought that "SET active = (0)" should be "SET active = 0"

    Comment


    • #3
      I originally had it without the parens. I did see another example that had the parens. Basically, I was to the point of "Oh well, can't do any harm, except for blow up." ;-)

      Comment


      • #4
        Hi all,

        I'm still working on my soft delete issue with @SQLDelete. I've changed things up a bit in hopes that a little experimentation would yield some sort of result.

        Here is what I've found so far.

        I created a base entity class called EntityBase as a mapped superclass. I then created a "Person" mapped superclass that extends EntityBase. I create a concrete entity that extends Person.

        I put the @SQLDelete command in the EntityBase thinking that every class that extends Entity base would then override the default hibernate/JPA delete method.

        So Entity base now looks like this.

        Code:
        @MappedSuperclass
        @Configurable
        @RooJavaBean
        @RooToString
        @RooEntity(mappedSuperclass = true)
        @SQLDelete(sql="UPDATE entitybase SET active = 0 WHERE id = ?")
        public class EntityBase { ...
        
        ... }
        When I debug through the code, it no longer throws the error I mentioned above, but instead of actually running the SQL I have in the @SQLDelete the normal JPA remove method is called. Is it possible to use @SQLDelete on a mapped superclass?

        Does anyone have any idea what I could be doing wrong?

        Comment

        Working...
        X