Persistence4j 1.1发布,Java ORM框架
程序员文章站
2022-03-06 22:41:40
...
近日,Persistence4j 1.1版本发布了,它是一个小型、轻量级的 Java 对象持久层类库,实现关系数据库和 Java 对象之间的持久化。此版本主要是对bug的修复,点击查看更新详情:http://code.google.com/p/persistence4j/
Persistence4j的目标就是开发一款操作简单使用方便的Java ORM框架,秉承这一设计理念设计出的Persistence4j拥有及其简单的配置,其语法基于JDK 1.6中的注释,使用起来十分方便。
示例代码:
//First lets create a simple pojo which you like to persist. @Entity(schema="library",table="book") public class Book{ @Column(isPrimaryKey=true) private String isbn; @Column private String title; @Column private int authorid; public Book(){ } public Book(String isbn, String title, int authorid){ this.isbn = isbn; this.title = title; this.authorid = authorid; } // getters } DataProviderFactory dataProviderFactory = new DataProviderFactoryImpl(config); String databaseName = "library"; String dbmsName = "mysql" boolean isTransactional = false; DataProvider dataProvider = dataProviderFactory.getDataProvider(databaseName, dbmsName, isTransactional); // Now lets create a object of Book class and persist it Book book = new Book("123432","TestBook",5); TransferUtil.registerClass(Book.class); GenericDAO<Book> genericDAO = new GenericDaoImpl<Book>(dataProvider.getDataFetcher()); //Persist Book genericDAO.createEntity(book); //Remove Book genericDAO.deleteEntity(book); //Test if Entity Exists genericDAO.isEntityExists(book); // findByPrimaryKey Object obj[] = new Object[1]; obj[0] = "123432"; genericDAO.findByPrimaryKey(Book.class, obj); //If you want to use transactions.This how to get TransactionService.Make sure //isTransactional variable should be true and underlying dbms supports ACID. TransactionService ts = dataProvider.getTransactionService(); try{ ts.beginTransaction(); genericDAO.createEntity(book); ts.commitTransaction(); }catch(Exception exp){ ts.rollbackTransaction(); } // Check the GenericDAO interface for all the available methods.. You can extend GenericDAOImpl and override the methods and add your own methods.
上一篇: freyja2多数据源版本
推荐阅读
-
基于Java ORM框架的使用详解
-
基于Java ORM框架的使用详解
-
轻量化 Java 开发框架Hasor 1.0.0 正式发布
-
一个类GraphQL的ORM数据访问框架发布
-
Java MVC + ORM框架 Nano Framework之环境搭建
-
一站式 Java Web 框架 firefly-2.0_03 发布
-
Minidao 1.6.2 版本发布,超轻量Java持久化框架(Hibernate完美助手)
-
Minidao_1.6.2 发布,超轻量 Java 持久化框架
-
【版本发布】JAVA微服务开发框架,Jeecg-P3 1.0.0 重构版本发布
-
Hibernate 4 beta3 发布,Java数据持久层框架