There hadn’t been a homicide in Daly City in more than two years, but the circumstances of the slaying that occurred near the close of 2016 mirrored the previous one in many ways.

Two weeks before the start of the new year, San Francisco State University student Ariana Hatami was beaten to death in her home, allegedly by her boyfriend, Frederick Tran, 24. The case shows similarities to the city’s last murder, when San Francisco social services employee Ruby Gim died at the hands her abusive partner in 2014.

There were clear differences: Hatami was 23 years old; Gim was 65. Hatami was a student studying business, while Gim had been an esteemed resident mother at Telegraph Hill Neighborhood Center.

But both women had been victims of domestic violence, both had been in relationships with their suspected killers, and both suspects had been ordered by police to stay away from their victims before the abuse became fatal.

Officials at San Mateo County’s Community Overcoming Relationship Abuse, a domestic abuse treatment center that advocates for victims, noted on Wednesday the “tricky dynamic” that comes with handling domestic violence cases.

“Each case is often unique in its own right,” said Melissa Lukin, executive director of the organization. “The constant is that oftentimes the victims are not aware of the degree of danger they’re in even if they have a temporary restraining order.”

Tran appeared in San Mateo County Superior Court in Redwood City on Tuesday, where he pleaded not guilty to charges of murder and violating a restraining, protective, or stay away order, among other counts, according to the San Mateo County district attorney’s office.

In Hatami’s case, she met Tran when they both worked at a Wells Fargo Bank in San Francisco, according to prosecutors. In June 2016, Tran vandalized her car after an argument. Things escalated in August 2016, when prosecutors say Tran struck Hatami in the face twice.

Daly City police responded and obtained an emergency protective order mandating that Tran, a San Francisco resident, stay away from Hatami, and he was charged with and convicted of misdemeanor domestic violence.

On Dec. 15, two days before Hatami’s death, Tran, back in jail for a probation violation, was bailed out on $25,000 bond. He reconnected with Hatami a day later and persuaded her to let him stay one night at her apartment, officials said.

Then, around 1:20 a.m. on Dec. 17, he allegedly killed her while she slept, repeatedly hitting her with a bottle. Her roommates heard the attack and held Tran as they called police.

Sgt. Ron Harrison, a Daly City Police Department spokesman, said the details of Hatami’s death fit a pattern of domestic violence that officers often see.

One in 4 women and 1 in 7 men experience domestic violence in San Mateo County, according to Community Overcoming Relationship Abuse.

Daly City leads the county in the number of referrals to the organization with about 1,070 in the 2016 fiscal year.

“It’s kind of a unique system,” Harrison said. “We look at all types of ways to just try to end the cycle of violence.”

Despite the group’s best efforts, some cases inevitably fall through the cracks, said Lukin.

“Restraining orders, while they have been proved to deter future violence ... there’s of course no guarantee that they keep someone safe,” she said.

Police officers related Hatami’s case to the city’s last homicide, where Gim was allegedly beaten to death by her longtime partner, Daniel Bryan Thomas, in her Daly City home — two years after obtaining a restraining order against him.

Friends described Thomas as having “enormous emotional and physical problems,” while prosecutors said Tran suffered from a “severe mental illness.”

Gim was found unresponsive in her Florence Street home in Daly City on April 30, 2014. Thomas, 67 at the time, was convicted of murder in October 2015.

But in 2012, Gim had filed a restraining order against him. A year later, Thomas had been arrested for an alleged domestic violence-related offense and charged with misdemeanor vandalism and violation of a court order, according to prosecutors.

Gim’s death came as a shock to her friends in San Francisco, where she was well known in the community. Local groups, including the Asian Women’s Shelter, rallied in a call for justice for Gim throughout Thomas’ trial.

Now, two years later, they expect to do the same for Hatami, said Beverly Upton, of the San Francisco Domestic Violence Consortium.

“We tried to show our collective outrage at her homicide,” Upton said of Gim. “We’re certainly interested in supporting in this current case as well.”

Chronicle staff writer Vivian Ho contributed to this report.

Jenna Lyons a San Francisco Chronicle staff writer. Email: jlyons@sfchronicle.com Twitter: @JennaJourno