-->
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.  [ 1 post ] 
Author Message
 Post subject: Deleting Embeddable objects
PostPosted: Wed Dec 10, 2008 4:44 pm 
Newbie

Joined: Wed Dec 10, 2008 4:25 pm
Posts: 1
I am struggling a bit finding information on the best approach to handle deleting things from a table that comes from an embeddable object.

The parent object will stick around in this case but daily I need to delete the records of the embeddable object that have the prior days date.

Maybe I am doing this the best way but I am not sure how this all works with the Embedded class.

The objects are simplified a bit below.

Code:
@Entity
public class Equity
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @Column(nullable = false, unique=true)
    private String symbol;

    private String name;

    @CollectionOfElements
    @JoinTable(name = "quotes", joinColumns = @JoinColumn(name = "equity_id", nullable = false))   
    @Sort(type = SortType.NATURAL)
    private SortedSet<Quote> quotes = new TreeSet<Quote>();

......

@Embeddable
public class Quote {

    @Parent
    private Equity equity;

    @Column(nullable = false)
    private Calendar time;

.......



What I am doing is in a QuoteDao object I have a method that creates a SQL query that deletes everything by date. I had tried to do it in HQL but was having problems maybe due to the @Embeddable not being an Entity.
The only thing I could make work was with straight SQL.

Is this approach below the best way to handle this situation? Any insight on this situation would be great to hear.

Code:
    public void deleteOldQuotes(Calendar date) {
        try {
           
            Query query = getCurrentSession().createSQLQuery("delete from quotes where time < :purgeBeforeDate");
            query.setCalendar("purgeBeforeDate", date);
            query.executeUpdate();
        }
        catch (HibernateException e) {
            throw new DaoException(e);
        }


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

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.