-->
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: Hibernate try to delete whenever I try to read the Set/List
PostPosted: Sat Dec 29, 2012 12:43 am 
Newbie

Joined: Sat Dec 29, 2012 12:41 am
Posts: 1
I have a List that supposed to be many-to-many (bidirectional)

This is the Filter class:

Code:
@ManyToMany(targetEntity=Serving.class)
@JoinTable(name = "BRIDGE_SERV_FILTER", joinColumns={
    @JoinColumn(name="filter_id")}, inverseJoinColumns={@JoinColumn(name="serving_id")})
private List<Serving> servings;
public List<Serving> getServing() { return this.servings; }
public void setServing(List<Serving> servings) { this.servings = servings; }


and this is the Serving class:

Code:
@ManyToMany(targetEntity=Filter.class)
    @JoinTable(name = "BRIDGE_SERV_FILTER", joinColumns={
        @JoinColumn(name="serving_id")}, inverseJoinColumns={@JoinColumn(name="filter_id")})
    private List<Filter> filters;
    public List<Filter> getFilters() { return filters;}
    public void setFilters(List<Filter> filters) { this.filters = filters;}


Then I supposed to call something to get all the filters from a serving, this is what I do (serv is of type Serving):

Code:
List<Filter> filters = serv.getFilters();

//iterate from all filter
for(Filter allf : allFilter)
{
    boolean mark_this = false;
    //..and matched the currently-iterated-all-filters with filter from
    //which the serving got
    for(com.pos.model.Filter f : filters)
    {
        //if matched, mark this current filter
        if (allf.getId().equals(f.getId()))
            mark_this = true;
    }
    tmodel.addRow(new Object[] { allf.getName(), mark_this });
}


that method is defined in the model, and it is static. so, when the form load, it calls like jTable.setTableModel(Filter.toTableModel(thisServing));

It reads, and it displayed the data. However, Hibernate also invokes delete as well:

Code:
Hibernate: select filter0_.filter_id as filter1_2_, filter0_.is_showable as is2_2_, filter0_.name as name2_ from DIM_FILTER filter0_ where is_showable=true
Hibernate: select filters0_.serving_id as serving1_4_1_, filters0_.filter_id as filter2_6_1_, filter1_.filter_id as filter1_2_0_, filter1_.is_showable as is2_2_0_, filter1_.name as name2_0_ from BRIDGE_SERV_FILTER filters0_ inner join DIM_FILTER filter1_ on filters0_.filter_id=filter1_.filter_id where filters0_.serving_id=?
Hibernate: delete from BRIDGE_SERV_FILTER where serving_id=?


In fact, I don't do any delete at all, and I don't ask hibernate to delete anything. Something that I don't understand might occur... how to prevent Hibernate from deletion? or there is anything that I done wrongly?

Funny things, if I do through command prompt, there is nothing wrong... the data still there if I read multiple of times. What I done wrong, please help me.


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.