Object-relational mapping (ORM) technologies have been proposed as a solution for the impedance mismatch problem between object-oriented applications and relational databases. Existing approaches use special-purpose mapping languages or are tightly integrated with the programming language. In this paper, we present MAGIC, an approach using bidirectional query and update views, based on a generic metamodel and a generic mapping language. The mapping language is based on second-order tuple-generating dependencies and allows arbitrary restructuring between the application model and the database schema. Due to the genericity of our approach, the core part including mapping generation and mapping composition is independent of the modeling languages being employed. We show the formal basis of MAGIC and how queries including aggregation can be defined using an easy to use query API. The scalability of our approach is shown in the evaluation using the TPC benchmark.