{"id":25569595,"url":"https://github.com/apache/cayenne","last_synced_at":"2025-05-14T22:08:55.755Z","repository":{"id":574248,"uuid":"206350","full_name":"apache/cayenne","owner":"apache","description":"Mirror of Apache Cayenne","archived":false,"fork":false,"pushed_at":"2025-05-05T18:41:50.000Z","size":93857,"stargazers_count":326,"open_issues_count":31,"forks_count":138,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-05-10T17:16:17.464Z","etag":null,"topics":["cayenne","database","java","library","network-client","network-server","web-framework","xml"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apache.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2009-05-21T01:05:37.000Z","updated_at":"2025-04-20T17:15:25.000Z","dependencies_parsed_at":"2024-03-18T15:47:20.353Z","dependency_job_id":"3c937ddb-8589-4831-9979-7b45ac32ed36","html_url":"https://github.com/apache/cayenne","commit_stats":{"total_commits":6865,"total_committers":72,"mean_commits":95.34722222222223,"dds":0.5147851420247633,"last_synced_commit":"0cb56279caad27b9ed928d021de746237b8a30a1"},"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcayenne","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcayenne/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcayenne/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fcayenne/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apache","download_url":"https://codeload.github.com/apache/cayenne/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254050664,"owners_count":22006335,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cayenne","database","java","library","network-client","network-server","web-framework","xml"],"created_at":"2025-02-21T00:02:31.195Z","updated_at":"2025-05-14T22:08:55.722Z","avatar_url":"https://github.com/apache.png","language":"Java","readme":"\u003c!--\n\tLicensed to the Apache Software Foundation (ASF) under one\n\tor more contributor license agreements.  See the NOTICE file\n\tdistributed with this work for additional information\n\tregarding copyright ownership.  The ASF licenses this file\n\tto you under the Apache License, Version 2.0 (the\n\t\"License\"); you may not use this file except in compliance\n\twith the License.  You may obtain a copy of the License at\n\t\n\thttps://www.apache.org/licenses/LICENSE-2.0\n\t\n\tUnless required by applicable law or agreed to in writing,\n\tsoftware distributed under the License is distributed on an\n\t\"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n\tKIND, either express or implied.  See the License for the\n\tspecific language governing permissions and limitations\n\tunder the License.   \n--\u003e\nApache Cayenne\n==============\n\n[![Maven Central](https://img.shields.io/maven-central/v/org.apache.cayenne/cayenne-server/4.2.svg)](https://cayenne.apache.org/download/)\n[![Build Status](https://github.com/apache/cayenne/actions/workflows/verify-deploy-on-push.yml/badge.svg?branch=master)](https://github.com/apache/cayenne/actions/workflows/verify-deploy-on-push.yml)\n\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://cayenne.apache.org\"\u003e\u003cimg src=\"https://cayenne.apache.org/img/cayenne_illustr3-30e8b8fa06.png\" width=\"261\" height=\"166\" alt=\"Apache Cayenne Logo\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n[Apache Cayenne](https://cayenne.apache.org) is an open source persistence framework licensed under the Apache License, providing object-relational mapping (ORM) and remoting services. \n\nTable Of Contents\n-----------------\n\n* [Quick Start](#quick-start)\n    * [Create Project](#create-xml-mapping)\n        * [Cayenne Modeler](#modeler-gui-application)\n        * [Maven plugin](#maven-plugin)\n        * [Gradle plugin](#gradle-plugin)\n    * [Include Cayenne Into Project](#include-cayenne-into-project)\n    * [Create Cayenne Runtime](#create-cayenne-runtime)\n    * [Create New Objects](#create-new-objects)\n    * [Queries](#queries)\n        * [Select Objects](#select-objects)\n        * [Aggregate Functions](#aggregate-functions)\n        * [Raw SQL queries](#raw-sql-queries)\n* [Documentation](#documentation)\n* [About](#about)\n* [License](#license)\n* [Collaboration](#collaboration)\n\n\nQuick Start\n----------------\n\n#### Create XML mapping\n\n##### Modeler GUI application\n\nYou can use Cayenne Modeler to manually create Cayenne project without DB.\nBinary distributions can be downloaded from https://cayenne.apache.org/download/\n\n[![Modeler](https://cayenne.apache.org/img/cayenne-modeler-40rc1-24b0368dc2.png)](https://cayenne.apache.org/download/)\n\nSee tutorial https://cayenne.apache.org/docs/4.2/getting-started-guide/ \n\n##### Maven plugin\n\nAdditionally, you can use Cayenne Maven (or [Gradle](#gradle-plugin)) plugin to create model based on existing DB structure.\nHere is example of Cayenne Maven plugin setup that will do it:\n\n```xml\n\u003cplugin\u003e\n    \u003cgroupId\u003eorg.apache.cayenne.plugins\u003c/groupId\u003e\n    \u003cartifactId\u003ecayenne-maven-plugin\u003c/artifactId\u003e\n    \u003cversion\u003e4.2.1\u003c/version\u003e\n\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.mysql\u003c/groupId\u003e\n            \u003cartifactId\u003emysql-connector-j\u003c/artifactId\u003e\n            \u003cversion\u003e8.4.0\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n\n    \u003cconfiguration\u003e\n        \u003cmap\u003e${project.basedir}/src/main/resources/demo.map.xml\u003c/map\u003e\n        \u003ccayenneProject\u003e${project.basedir}/src/main/resources/cayenne-demo.xml\u003c/cayenneProject\u003e\n        \u003cdataSource\u003e\n            \u003curl\u003ejdbc:mysql://localhost:3306/cayenne_demo?nullNamePatternMatchesAll=true\u003c/url\u003e\n            \u003cdriver\u003ecom.mysql.cj.jdbc.Driver\u003c/driver\u003e\n            \u003cusername\u003euser\u003c/username\u003e\n            \u003cpassword\u003epassword\u003c/password\u003e\n        \u003c/dataSource\u003e\n        \u003cdbImport\u003e\n            \u003cdefaultPackage\u003eorg.apache.cayenne.demo.model\u003c/defaultPackage\u003e\n        \u003c/dbImport\u003e\n    \u003c/configuration\u003e\n\u003c/plugin\u003e\n```\n\nRun it:\n```bash\nmvn cayenne:cdbimport\nmvn cayenne:cgen\n```\nSee tutorial https://cayenne.apache.org/docs/4.2/getting-started-db-first/\n\n##### Gradle plugin\n\nAnd here is example of Cayenne Gradle plugin setup:\n\n```gradle\nbuildscript {\n    repositories {\n        mavenCentral()\n    }\n    dependencies {\n        classpath 'org.apache.cayenne.plugins:cayenne-gradle-plugin:4.2.1'\n        classpath 'com.mysql:mysql-connector-j:8.4.0'\n    }\n}\n\napply plugin: 'org.apache.cayenne'\ncayenne.defaultDataMap 'demo.map.xml'\n\ncdbimport {   \n    cayenneProject 'cayenne-demo.xml'\n\n    dataSource {\n        driver 'com.mysql.cj.jdbc.Driver'\n        url 'jdbc:mysql://127.0.0.1:3306/cayenne_demo?nullNamePatternMatchesAll=true'\n        username 'user'\n        password 'password'\n    }\n\n    dbImport {\n        defaultPackage = 'org.apache.cayenne.demo.model'\n    }\n}\n\ncgen.dependsOn cdbimport\ncompileJava.dependsOn cgen\n```\n\nRun it:\n```bash\ngradlew build\n```\n\n#### Include Cayenne into project\n\n##### Maven\n\n```xml\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.apache.cayenne\u003c/groupId\u003e\n        \u003cartifactId\u003ecayenne-server\u003c/artifactId\u003e\n        \u003cversion\u003e4.2.1\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n\n##### Gradle\n\n```gradle\ncompile group: 'org.apache.cayenne', name: 'cayenne-server', version: '4.2.1'\n \n// or, if Gradle plugin is used\ncompile cayenne.dependency('server')\n```\n\n#### Create Cayenne Runtime\n\n```java\nServerRuntime cayenneRuntime = ServerRuntime.builder()\n    .addConfig(\"cayenne-demo.xml\")\n    .dataSource(DataSourceBuilder\n             .url(\"jdbc:mysql://localhost:3306/cayenne_demo\")\n             .driver(\"com.mysql.cj.jdbc.Driver\")\n             .userName(\"username\")\n             .password(\"password\")\n             .build())\n    .build();\n```\n\n#### Create New Objects\n\n```java\nObjectContext context = cayenneRuntime.newContext();\n\nArtist picasso = context.newObject(Artist.class);\npicasso.setName(\"Pablo Picasso\");\npicasso.setDateOfBirth(LocalDate.of(1881, 10, 25));\n\nGallery metropolitan = context.newObject(Gallery.class);\nmetropolitan.setName(\"Metropolitan Museum of Art\");\n\nPainting girl = context.newObject(Painting.class);\ngirl.setName(\"Girl Reading at a Table\");\n\nPainting stein = context.newObject(Painting.class);\nstein.setName(\"Gertrude Stein\");\n\npicasso.addToPaintings(girl);\npicasso.addToPaintings(stein);\n\ngirl.setGallery(metropolitan);\nstein.setGallery(metropolitan);\n\ncontext.commitChanges();\n```\n\n#### Queries\n\n##### Select Objects\n\n```java\nList\u003cPainting\u003e paintings = ObjectSelect.query(Painting.class)\n        .where(Painting.ARTIST.dot(Artist.DATE_OF_BIRTH).year().lt(1900))\n        .prefetch(Painting.ARTIST.joint())\n        .select(context);\n```\n\n##### Aggregate functions\n\n```java\n// this is artificial property signaling that we want to get full object\nProperty\u003cArtist\u003e artistProperty = Property.createSelf(Artist.class);\n\nList\u003cObject[]\u003e artistAndPaintingCount = ObjectSelect.columnQuery(Artist.class, artistProperty, Artist.PAINTING_ARRAY.count())\n    .where(Artist.ARTIST_NAME.like(\"a%\"))\n    .having(Artist.PAINTING_ARRAY.count().lt(5L))\n    .orderBy(Artist.PAINTING_ARRAY.count().desc(), Artist.ARTIST_NAME.asc())\n    .select(context);\n\nfor(Object[] next : artistAndPaintingCount) {\n    Artist artist = (Artist)next[0];\n    long paintingsCount = (Long)next[1];\n    System.out.println(artist.getArtistName() + \" has \" + paintingsCount + \" painting(s)\");\n}\n\n```\n\n##### Raw SQL queries\n\n```java\n// Selecting objects\nList\u003cPainting\u003e paintings = SQLSelect\n    .query(Painting.class, \"SELECT * FROM PAINTING WHERE PAINTING_TITLE LIKE #bind($title)\")\n    .params(\"title\", \"painting%\")\n    .upperColumnNames()\n    .localCache()\n    .limit(100)\n    .select(context);\n\n// Selecting scalar values\nList\u003cString\u003e paintingNames = SQLSelect\n    .scalarQuery(String.class, \"SELECT PAINTING_TITLE FROM PAINTING WHERE ESTIMATED_PRICE \u003e #bind($price)\")\n    .params(\"price\", 100000)\n    .select(context);\n\n// Insert values\nint inserted = SQLExec\n    .query(\"INSERT INTO ARTIST (ARTIST_ID, ARTIST_NAME) VALUES (#bind($id), #bind($name))\")\n    .paramsArray(55, \"Picasso\")\n    .update(context);\n\n```\n\nDocumentation\n----------------\n\n#### Getting Started\n\nhttps://cayenne.apache.org/docs/4.2/getting-started-guide/\n\n#### Getting Started Db-First\n\nhttps://cayenne.apache.org/docs/4.2/getting-started-db-first/\n\n#### Full documentation\n\nhttps://cayenne.apache.org/docs/4.2/cayenne-guide/\n\n#### JavaDoc\n\nhttps://cayenne.apache.org/docs/4.2/api/\n\nAbout\n-----\n\nWith a wealth of unique and powerful features, Cayenne can address a wide range of persistence needs. Cayenne seamlessly binds one or more database schemas directly to Java objects, managing atomic commit and rollbacks, SQL generation, joins, sequences, and more.\n\nCayenne is designed to be easy to use, without sacrificing flexibility or design. To that end, Cayenne supports database reverse engineering and generation, as well as a Velocity-based class generation engine. All of these functions can be controlled directly through the CayenneModeler, a fully functional GUI tool. No cryptic XML or annotation based configuration is required! An entire database schema can be mapped directly to Java objects within minutes, all from the comfort of the GUI-based CayenneModeler.\n\nCayenne supports numerous other features, including caching, a complete object query syntax, relationship pre-fetching, on-demand object and relationship faulting, object inheritance, database auto-detection, and generic persisted objects. Most importantly, Cayenne can scale up or down to virtually any project size. With a mature, 100% open source framework, an energetic user community, and a track record of solid performance in high-volume environments, Cayenne is an exceptional choice for persistence services.\n\nCollaboration\n--------------\n\n* [Bug/Feature Tracker](https://issues.apache.org/jira/browse/CAY)\n* [Mailing lists](https://cayenne.apache.org/mailing-lists.html)\n* [Support](https://cayenne.apache.org/support.html)\n* [Contributing](https://cayenne.apache.org/how-can-i-help.html)\n\nLicense\n---------\nCayenne is available as free and open source under the [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0).\n","funding_links":[],"categories":["数据库开发"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fcayenne","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapache%2Fcayenne","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fcayenne/lists"}