-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibnernate Spring Roo and @SQLDelete
PostPosted: Thu Nov 17, 2011 9:26 pm 
Newbie

Joined: Thu Nov 17, 2011 3:52 pm
Posts: 1
Hello all,

Has anyone had any success with using the Hibernate specific annotation of @SQLDelete in a Spring 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
Spring Roo 1.2M1
Spring MVC 3
JPA with Hibernate as my provider
MariaDB 5.3.x



Found this information http://featurenotbug.com/2009/07/soft-deletes-using-hibernate-annotations/ though it is a bit dated.

I first tried it as the above link suggests and I place the @SQLDelete in my concrete entity class that extends, a mapped super class and I receive the following error:

Code:
ERROR org.hibernate.util.JDBCExceptionReporter - Parameter index out of range (2 > number of parameters, which is 1).


I'm not sure why I am getting this so I decided to experiment.

During my experimentation, 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 EntityBase 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?

Is it possible to use @SQLDelete in a mapped super class? If not can I use it on a class that extends a mapped superclass?

I've looked around and I can't really find out any really good detailed information.

Any help or guidance on this would be greatly appreciated.

Thanks!
John


Top
 Profile  
 
 Post subject: Re: Hibnernate Spring Roo and @SQLDelete
PostPosted: Mon Jan 21, 2013 2:19 pm 
Newbie

Joined: Mon Jan 21, 2013 1:13 pm
Posts: 1
I know that it's a ancient post, but maybe helps other users

I my case I obtain the same error

Code:
ERROR org.hibernate.util.JDBCExceptionReporter - Parameter index out of range (2 > number of parameters, which is 1).


Was caused by the version column that is handled internally by Spring Roo

Instead of
Code:
@SQLDelete(sql="UPDATE entitybase SET active = 0 WHERE id = ?")

Use
Code:
@SQLDelete(sql="UPDATE entitybase SET active = 0 WHERE id = ?  and version=?")


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.