Crop-raiding by elephants are a problem in Africa - an issue that has long vexed small farmers as elephants trample and consume crops, leading to food insecurity, lost opportunity costs, and even death - of elephants and farmers.
Scientists think elephants are afraid of bees because they dislike being stung in the soft tissue that's present inside their trunks and around their eyes. Elephants have pheromone receptors and have learned to identify and avoid the alarm pheromones honeybees release when they sense a threat.
Beehive fences are a small piece of genius that is growing quickly in Africa. The base logic is that hives are constructed around a farm - around 8 to 10 metres apart. Elephants approaching the farm identify bees on approach and turn away. Systems have been developed with real and dummy hives with connecting wires that cause the hives to swing if touched anywhere, and release bees from all hives.
An 80% success rate is generally claimed with the fence and most use a Top Bar Hives and Langstroth Hives as they swing efficiently as well as providing good honey yields for the farmers.
While beehive fences humanely deterring elephants from entering farms, bees also provide honey and pollination services which helps increase the crop yields of the farms they protect. Honey is sold by fence builders, farmers or in a kind of co-op arrangement to provide diversified income.
Ecological solutions that resist killing any kind of animal are always a useful outcome, especially with the issues we have with diminishing species.