Although the h and k lines of MgII are expected to be of great interest for probing the upper solar chromosphere, relatively little is known about their polarization properties which encode the information on the magnetic field. Here we report the first results of an investigation whose main goal is to understand the physical mechanisms that control the scattering polarization across these resonance lines and to achieve a realistic radiative transfer modeling in the presence of arbitrary magnetic fields. We show that the joint action of partial frequency redistribution (PRD) and quantum interference between the two excited J-levels produces a complex fractional linear polarization (Q/I) pattern with large polarization amplitudes in the blue and red wings, and a negative feature in the spectral region between the two lines. Another remarkable peculiarity of the Q/I profile is a conspicuous antisymmetric signal around the center of the h line, which cannot be obtained unless both PRD and J-state interference effects are taken into account. In the core of the k line, PRD effects alone produce a triplet peak structure in the Q/I profile, whose modeling can be achieved also via the two-level atom approximation. In addition to the Hanle effect in the core of the k line, we emphasize also the diagnostic potential of the circular polarization produced by the Zeeman effect in the h and k lines, as well as in other MgII lines located in their wings.