orm

What is the best query strategy and entities configuration when using a second level cache

偶尔善良 提交于 2020-01-25 08:33:05
问题 What is the best query strategy and the best configuration for my entities when the second level cache is activated. For example I have two entities User and Group with these relations : One User to Many Group : the groups owned by the user. Here a collection of Group in the User class and a User attribute (the owner) in the Group class. Many User to Many Group with attributes (status, date etc.) : the members of the groups. Because of the additionnals attibutes there is a specific class to

MyBatis源码的学习(19)---如何将jdbc的返回结果resultSet处理为我们想要的java类型

 ̄綄美尐妖づ 提交于 2020-01-25 07:04:09
处理结果集的逻辑:ResultSetHandler---->TypeHandler @Override public <E> List<E> doQuery(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException { Statement stmt = null; try { Configuration configuration = ms.getConfiguration(); StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, resultHandler, boundSql); //这一步完成connection建立,statement对象的创建,参数的赋值操作 stmt = prepareStatement(handler, ms.getStatementLog()); //我们今天看者一行,如何将jdbc返回的resultSet对象处理为我们想要的java类型 return handler.query(stmt, resultHandler);

mybatis 第一个项目

谁说我不能喝 提交于 2020-01-25 01:21:01
首先先了解一下mybatis的概念和架构 概念 先了解ORM(Object/Relational Mapping),即对象关系映射,它用来完成面向对象编程语言到关系数据库的映射。简单来说ORM的作用就是将持久化对象的增删改查操作转换成对关系数据库的操作。 ORM的基本映射关系: 数据表映射 数据表的行(一行单表一个数据)映射对象(实例) 数据表的列(字段)映射对象的属性 mybatis本来是apache的开源项目ibatis,后来移植到google code,并更名为现在的名字mybatis。 mybatis的优点: 支持定制化SQL,存储过程,以及高级映射。 避免JDBC代码,以及配置。 对结果集进行封装。 可以使用注解,将接口和java中的pojo映射成数据库中的记录。 mybatis的思想:将程序中大量的sql语句抽离出来,在配置文件中配置,以实现sql的灵活。 mybatis并不是一个完成的ORM框架,他可以通过编写sql,使得访问数据库更加灵活。准确的说是半自动化的ORM框架,是一种sql mapping框架。 架构 mybatis的架构分为三层: 接口层:提供给开发人员的API接口,通过这些API来操作数据库。 数据处理层:完成一次数据库请求,只要的流程是sql查找、sql解析、sql执行,以及对结果集的处理。 基础支撑层:负责最底层的东西,也是公用的东西,包括连接管理

Any real use for table-per-concrete-class with implicit polymorphism?

*爱你&永不变心* 提交于 2020-01-24 14:07:38
问题 If mapping inheritance using table per concrete class, while mapping concrete classes simply just as any other class (without union-subclass), NHibernate allows same PKs across subclasses. For example if you have BillingDetails and subclasses CreditCard and BankAccount, requesting all BillingDetails will get you all records from both tables, which can in turn have duplicate primary keys, which can be problematic due to not valid business identity of those objects. This of course is not the

Any real use for table-per-concrete-class with implicit polymorphism?

浪子不回头ぞ 提交于 2020-01-24 14:05:09
问题 If mapping inheritance using table per concrete class, while mapping concrete classes simply just as any other class (without union-subclass), NHibernate allows same PKs across subclasses. For example if you have BillingDetails and subclasses CreditCard and BankAccount, requesting all BillingDetails will get you all records from both tables, which can in turn have duplicate primary keys, which can be problematic due to not valid business identity of those objects. This of course is not the

Any real use for table-per-concrete-class with implicit polymorphism?

假如想象 提交于 2020-01-24 14:04:04
问题 If mapping inheritance using table per concrete class, while mapping concrete classes simply just as any other class (without union-subclass), NHibernate allows same PKs across subclasses. For example if you have BillingDetails and subclasses CreditCard and BankAccount, requesting all BillingDetails will get you all records from both tables, which can in turn have duplicate primary keys, which can be problematic due to not valid business identity of those objects. This of course is not the

尝试手写orm框架

主宰稳场 提交于 2020-01-24 11:56:59
前言: 在使用各种的orm框架的过程中,菜鸟的我始终没有搞懂底层实现技术,最近刚好没事找了些视频和资料了解一点皮毛,想记录下,大家勿喷。 所谓的ORM(Object Relational Mapping) 对象关系映射 官方解释是通过使用描述对象和数据库之间映射的元数据,将面向对象程序的对象自动持久化到关系数据库中。 个人理解就是一个数据库访问的帮助类,可以让我们不用手写sql,就完成数据库的访问 使用的技术: 泛型、反射、特性、扩展 摸索步骤: step1 新建项目,建几个类库,大家熟悉的三层。 step2: 在数据访问层新建一个sqlhelper 类; 2.1 添加一个数据查询的方法,还需要添加model层添加SysUser,完成实体与表映射,实现代码 如下 1 public class SysUser 2 { 3 public long Id { get; set; } 4 public string Login_Name { get; set; } 5 public string Name { get; set; } 6 public string Icon { get; set; } 7 public string Password { get; set; } 8 public string Salt { get; set; } 9 public string Tel {

Hibernate cascade delete on a bag

偶尔善良 提交于 2020-01-24 11:27:12
问题 Having built most of my DAL using NHibernate, I've now discovered that the SQL Server's Cascade On Delete rules also need to be taken into account in my HBM files too. I've been using bags for all my collections, but there doesn't seem to be a way to add a cascade="delete" attribute to a bag. I can change all my bags to sets, but that appears to mean I have changing all my IList<>s on my models to PersistentGenericSet<>s, which I don't really fancy doing. Any advice? Anthony 回答1: There are

Strange Doctrine EntityNotFoundException

£可爱£侵袭症+ 提交于 2020-01-24 11:23:50
问题 I came across a strange behavior with Symfony and Doctrine issue, which actually found out that may be related to this bug. request.CRITICAL: Uncaught PHP Exception Doctrine\ORM\EntityNotFoundException: "Entity was not found." at /dev/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php line 177 {"exception":"[object] (Doctrine\ORM\EntityNotFoundException(code: 0) To provide some code samples: $nextItems = $this->itemManager->findNextItemByCatId($catId, 2, $allItems); and then I am

Performance difference of Native SQL(using MySQL) vs using Hibernate ORM?

丶灬走出姿态 提交于 2020-01-24 05:37:31
问题 I am using Spring MVC for an application that involved a multilevel back end for management and a customer/member front end. The project was initially started with no framework and simple native JDBC calls for database access. As the project has grown significantly(as they always do) I have made more significant database calls, sometimes querying large selection sizes. I am doing what I can to treat my db calls to closely emulate Object Relational Mapping best practices, but am still just