How to make HABTM bulk-assignment transactional?

I have a model with a has_and_belongs_to_many relationship that I'd
like to bulk-assign a bunch of IDs to, as well as other attributes. Is
there any way I can do this in a transaction without having to
explicitly demarcate it?

Code looks something like this:

class Resource
  has_and_belongs_to_many :groups

class ResourceController
  def update
    @resource = Resource.find(params[:id])
    @resource.group_ids = params[:group_ids].split(',')
    if @resource.update_attributes(params[:resource])

What I find is that as soon as I call group_ids, the changes are
written to the database. I want it to happen in the same transaction
that update_attributes uses. I'd rather not have to declare a
transaction block, because there are already relationships between
these objects.

Any ideas?