Thursday, May 17, 2012

Firefox 12 Way Too Slow on Fedora 16

I found these useful tips on how to customize Firefox and get it faster.
Now, when I have time I need to test if they're working because in the meantime I switched to Chrome despite my lifelong appreciation for the Fox. This is to tell you how unusable it has become.

Monday, May 14, 2012

No Cascade Delete on a Collection Relationship

I had the following relationship in a UserAnswer, the answer(s) a user can give to a question in a survey:

     public SortedSet getSelectedAnswers()

I wanted to propagate all persistence operations to the collection except DELETE. I didn't want an Answer to be deleted when all UserAnswers were removed.
This is how it worked for me: 

    @ManyToMany(targetEntity=Answer.class, cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
    @Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
    @JoinTable(name="userAnswer_answers",
            joinColumns=@JoinColumn(name="userAnswer_fk"),
            inverseJoinColumns=@JoinColumn(name="answer_fk"))
    @Sort(type = SortType.COMPARATOR, comparator = AnswerPositionComparator.class)
    public SortedSet getSelectedAnswers() {
       
        return selectedAnswers;
    }


If you don't use CascadeType.ALL, Hibernate doesn't cascade the save of an entity's Collection properties when using the PERSIST annotation. You have to explicitly use the org.hibernate.annotations.CascadeType.SAVE_UPDATE annotation.

Source here.

Friday, May 11, 2012

Eclipse Code Templates

If you'd like to have your own text additions to a new file upon its creation, you can customize the way it is created with code templates.
Go to Window --> Properties --> Java --> Code Styles --> Code Templates.

You can customize comments and code components in this way at Eclipse level or project level.