How to Make It
In a large bowl, soak the kidney and pinto beans in cold water overnight. Soak the black beans overnight in another bowl.
Drain the two bowls of beans separately and transfer each batch to a large saucepan. Add 1 ham hock or piece of bacon to each saucepan. Add 2 quarts of the water and 4 cups of the chicken stock to the pinto and kidney beans. Add the remaining 1 quart of water and 2 cups of chicken stock to the black beans.
Bring the beans in the saucepans to a boil, then cover partially and cook over low heat until they are almost tender, about 1 hour for the kidney and pinto beans and 35 minutes for the black beans. Drain the beans; reserve the kidney and pinto bean cooking liquid. Discard the black bean cooking liquid.
Remove the meat from the ham hocks and shred; reserve the ham hock fat and 1 bone. If using bacon, trim the fat and cut the meat into pieces. Reserve the bacon fat.
Heat a medium cast-iron skillet. Add the ancho chiles and toast, pressing down with a spatula until they are fragrant and blistered, about 30 seconds. Transfer to a heatproof bowl, cover with boiling water and soak until softened, about 15 minutes. Drain and finely chop.
In a large, enameled cast-iron casserole, cook the ham hock fat or bacon fat in the vegetable oil over moderately high heat until the fat is crisp, about 5 minutes. Discard the fat. Add the onions, jalapeños, garlic and ancho chiles and cook over moderate heat, stirring occasionally, until softened, about 8 minutes. Add the reserved ham or bacon meat and cook, stirring until golden, about 3 minutes. Add the barbecue sauce, tomato paste, the reserved ham hock bone and all of the drained beans. Stir in 4 cups of the reserved bean cooking liquid and season with salt and pepper. Cover and cook over moderately low heat, until the beans are tender and the gravy is thick, about 1 1/2 hours longer; add more of the bean cooking liquid if the beans seem dry. Discard the ham hock bone and transfer the beans to a large shallow baking dish or individual crocks.
Preheat the oven to 425°. In a medium bowl, toss the cracker crumbs with the cheese. Sprinkle the mixture over the beans. Bake the gratin for about 25 minutes, or until bubbling and golden. Serve with lime wedges.